In article <87eitg267e....@benfinney.id.au>, Ben Finney <ben+pyt...@benfinney.id.au> wrote: >Matthew Wilson <m...@tplus1.com> writes: >> >> from datetime import datetime >> def f(c="today"): >> if c == "today": >> c = datetime.today() >> return c.date() > >* You're re-binding the parameter name âcâ to something different within > the function: it starts out bound to the input string, but by the time > the function ends you're expecting it to be bound to a datetime > object. Instead, you should be binding a *different* name to the > datetime object you create inside the function, and using that for the > return statement.
Actually, I disagree that this is necessarily bad, although it's often a yellow flag. The context in which it is possibly appropriate is when you want your function to handle multiple types for one parameter and you always cast the data to one single type. -- Aahz (a...@pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha
-- http://mail.python.org/mailman/listinfo/python-list