Default parameters

Carl Banks imbosol at aerojockey.invalid
Thu Dec 18 06:26:49 EST 2003


Terry Reedy wrote:
> 
> 
> 
> "Stian S?iland" <stain at stud.ntnu.no> wrote in
> message
> news:slrnbtvte6.tnk.stain at ozelot.stud.ntnu.no...
>> When is this issue going to be resolved? Enough
> newbie-pythoners have
>> made this mistake now.
> 
> I am puzzled as to why.  When I learned Python, I
> read something to the effect that default value
> expressions are evaluated at definition time.  I
> understood that the resulting objects were saved
> for later use (parameter binding) when needed (as
> default for value not given).  I believed this and
> that was that.


I am puzzled as to why you're puzzled.  Not everyone who reads the
manual pays attention to the time of evaluation explanation, if the
manual they're using even covers.  Not everyone stops and says, "Oh my
God, I don't know whether this is evaluated when the function is
defined or called.  I better find out."  (And of course, not everyone
reads the manual.)

It seems that most people who haven't thought about time of evaluation
tend to expect it to be evaluated when the function is called; I know
I would expect this.  (I think I even made the mistake.)



-- 
CARL BANKS                      http://www.aerojockey.com/software
"If you believe in yourself, drink your school, stay on drugs, and
don't do milk, you can get work." 
          -- Parody of Mr. T from a Robert Smigel Cartoon




More information about the Python-list mailing list