__iadd__ and fellows missing (Python 2.2)

Fernando Pérez fperez528 at yahoo.com
Mon Apr 15 15:10:21 EDT 2002


Mike C. Fletcher wrote:

> Rather than confuse Tim further with abstract samples of where I want to
> define a "NULL" default argument, here's a particular example of where
> the "NULL pattern" I've described is used:
> 

[snip]

This is one of the few perlisms I still miss after having transitioned to 
python. In perl you have the 'if defined($x)' idiom for checking whether a 
variable is even defined (deeper than truth testing). This allows checking 
for variable names which may be undefined without triggering an error. I'd 
love to have a similar option in python:

def foo(x,y=Undef,z=10):
  if y is not Undef:
        ...

The use would be that an explicit
x=Undef
assignment is equivalent to 'del x', because you make a variable undefined via 
it. But in function prototypes, such a definition simply means 'this argument 
is optional, can be given either positionally or by name, but it has no 
default value because I want to explicitly check whether it was passed or 
not'.

I know this can be implemented with special patterns, so maybe my rambling 
here isn't too justified and 'pythonic' :). Need more coffee today, it's 
Monday.

cheers,

f.



More information about the Python-list mailing list