473,387 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

parameter name conflict. How to solve?

Dear list,

If you ask: why do you choose these names? The answer is: they need to
be conformable with other functions, parameter names.

I have a function that pretty much like:

def output(output=''):
print output

and now in another function, I need to call output function, with again
keyword parameter output

def func(output=''):
output(output=output)

Naturally, I get 'str' object is not callable. Is there a way to tell
func that the first output is actually a function? (like in C++,
::output(output) )

Thanks.
Bo
Jul 18 '05 #1
7 1583
Bo Peng wrote:
Dear list,

If you ask: why do you choose these names? The answer is: they need to
be conformable with other functions, parameter names.

I have a function that pretty much like:

def output(output=''):
print output

and now in another function, I need to call output function, with again
keyword parameter output

def func(output=''):
output(output=output)

Naturally, I get 'str' object is not callable. Is there a way to tell
func that the first output is actually a function?


Yes, but you probably don't want to go that way. Can you explicitly
indicate the location of the 'output' function? e.g.:

py> def output(output=''):
.... print output
....
py> def func(output=''):
.... __import__(__name__).output(output)
....
py> func('abc')
abc

or possibly:

py> def func(output=''):
.... globals()['output'](output)
....
py> func('abc')
abc

This is easier if output is in another module -- you can just write
something like:
outputmodule.output(output)

STeVe
Jul 18 '05 #2
Bo Peng wrote:
def func(output=''):
output(output=output)

Naturally, I get 'str' object is not callable. Is there a way to tell
func that the first output is actually a function? (like in C++,
::output(output) )


output_alias = output

def func (output=''):
output_alias(output=output)

Daniel
Jul 18 '05 #3
Bo Peng wrote:
def func(output=''):
output(output=output)

Naturally, I get 'str' object is not callable. Is there a way to tell
func that the first output is actually a function? (like in C++,
::output(output) )


You could use a default argument:
def func(output='', output_fn=output):
output_fn(output=output)

Kent
Jul 18 '05 #4
Bo Peng a écrit :
Dear list,

If you ask: why do you choose these names? The answer is: they need to
be conformable with other functions, parameter names.

I have a function that pretty much like:

def output(output=''):
print output

and now in another function, I need to call output function, with again
keyword parameter output

def func(output=''):
output(output=output)

Naturally, I get 'str' object is not callable. Is there a way to tell
func that the first output is actually a function? (like in C++,
::output(output) )

Thanks.
Bo


What I'd suggest is :

def func(output=''):
gobals()["output"](output=output)

that way, the function resolution is still dynamic, but you explicitly
ask for a name global and not local ...

Pierre
Jul 18 '05 #5
Kent Johnson wrote:
Bo Peng wrote:
def func(output=''):
output(output=output)

Naturally, I get 'str' object is not callable. Is there a way to tell
func that the first output is actually a function? (like in C++,
::output(output) )

You could use a default argument:
def func(output='', output_fn=output):
output_fn(output=output)

Kent


Thank everyone for the quick responses. All methods work in general.
Since func() has to take the same parameter set as some other functins,
I can not use func(output='', output_fn=output). "output_alias=output"
etc are fine.

Bo
Jul 18 '05 #6
Bo Peng wrote:
Thank everyone for the quick responses. All methods work in general.
Since func() has to take the same parameter set as some other functins,
I can not use func(output='', output_fn=output). "output_alias=output"
etc are fine.


One suggestion that I haven't seen so far:

Where does this mysteriously named function 'output' come from? If it is
defined in another module, then simply call it qualified by the module
name.

i.e. if the code looks like:

from othermodule import output

def func(output=''):
output(output=output)

change it to:

import othermodule

def func(output=''):
othermodule.output(output=output)

Jul 18 '05 #7
Bo Peng wrote:
def func(output=''):
output(output=output)


Another solution that hasn't been mentioned yet:

def func(**kwds):
output(output = kwds['output'])

You might want to do some more checking on the
contents of kwds to make sure it doesn't
contain any other nonsense parameters.

--
Greg Ewing, Computer Science Dept,
University of Canterbury,
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: chunmok | last post by:
When compile using g++, following error messages appears. /usr/include/sys/sysinfo.h:101: `struct sysinfo_t sysinfo' redeclared as differe nt kind of symbol /usr/include/sys/systeminfo.h:77:...
9
by: John | last post by:
I am using two large libraries which both have an implementation of a "matrix" class. I have the source code for both. I need to use them in the same project and when I try to compile I get a...
6
by: Catherine Jones | last post by:
Hi all, we need urgent help in a matter. We are trying to pass a COM object from the client to server and are facing some problems in the same. We've our client in C# as well as the Server...
1
by: Wayne | last post by:
I have the following Namesapces (only for example, would not name them this way in production code) Wayne.Test.Data Wayne.Test.BR With in Wayne.Test.Data name space I have the following...
6
by: tizmagik | last post by:
I am having a lot of difficulty generating a CrossTab Query based report. I have looked online for several tutorials and whatnot but I have not been able to really find what I'm looking for, nor...
4
by: crystal | last post by:
I've checked the threads but haven't been able to come up with a solution to my issue. Help...... I have a simple form based on a table. Within the form is a subform that is also, through a Q,...
5
by: laurentc | last post by:
Dear all, I have several tables based on exactly the same fields (Key/Date/Price1/Price2). I do some statistics on the prices. However, as I have many different tables (the tables are...
1
by: mick | last post by:
Hi, if I add a record to a table in my database, everything goes well. When I then place the table in another database and link to it from my database I suddenly get a key conflict when I add a...
9
by: Meendar | last post by:
Hi, Below is my code snippet having only one form, <form> <input type ="radio" name="action" value="xyz" checked>xyz <input type ="radio" name="action" value="zyx">zyx <input type ="radio"...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.