Inheritance and forward references (prototypes)

Lie Ryan lie.1296 at gmail.com
Sun Jun 21 15:13:09 CEST 2009


Lorenzo Di Gregorio wrote:
> I had also thought of using "None" (or whatever else) as a marker but
> I was curious to find out whether there are better ways to supply an
> object with standard values as a default argument.
> In this sense, I was looking for problems ;-)
> 
> Of course the observation that "def" is an instruction and no
> declaration changes the situation: I would not have a new object being
> constructed for every instantiation with no optional argument, because
> __init__ gets executed on the instantiation but test=A() gets executed
> on reading 'def'.
> 
> At this point I think there is no other way than using a marker as
> suggested above multiple times, if I want to supply a new object with
> default values for non-passed arguments.

Using None as default for mutable default argument is the common idiom
for the problem you're having.



More information about the Python-list mailing list