Anonymus functions revisited

Ron radam2 at tampabay.rr.com
Tue Mar 22 22:56:57 CET 2005


On Tue, 22 Mar 2005 21:43:48 +0100, Bruno Desthuilliers
<bdesth.quelquechose at free.quelquepart.fr> wrote:

>Ron a écrit :
>(snip)
>>>>def dfv( arg = value):    
>> 
>>          return arg
> >
> >>> def dfv( arg = value):
>...     return arg
>...
>Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>NameError: name 'value' is not defined
>
>And sorry, but -1 for using exec here.


Yes, I cought that myself.  So...

try: z=z
except: z=0

or 

if 'z' not in locals():
    z = 0

Ok, thinking in more incremental terms...

Why should a function not create a local varable of an argument if the
varable doesn't exist and a default value is given?

So when:

Def dfv( v=0):
	return v

>>dfv()
0	    ;it creates the local copy in this case.

>>a = 25
>>dfv(a)
25          ;It used the given value as expected.

>>dfv(b)
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in -toplevel-
    dfv(b)
NameError: name 'b' is not defined

Why not let it set the local varable v to the default as it does when
no varable is specified?  

A function without a default would still give an error as expected.


:)
Ok no exec,  but what about the general syntax?

value = keyword (inputargs, command, outputargs)

I was thinking if it can be done with standard tuples, it has the
potential to be passed around easily and work from lists and
dictionaries. 

Ron




More information about the Python-list mailing list