def args idiom and signatures
Michel Pelletier
michel at digicool.com
Wed Jan 19 18:06:57 EST 2000
Emile van Sebille wrote:
>
> In /F's Standard Python Library I spotted:
>
> def _d(y, m, d, days=(0, 31, 59, ..., 334, 365)):
>
> where the balance of the function relies on days having this value.
>
> Trying to understand why it may be an argument vs defined within
> the function, I suspect that as the def is only processed to bytecode
> once, whereas an in-line assignment would be re-processed with
> each execution, that the decision is performance based.
You are correct. There are caveats, however, for instance, it is highly
recommened that these objects be used in a read-only fasion in a
multi-threaded program (or use locks).
> Now, in light of the various discussions pertaining to function
> signatures, it seems that this idiom presents a particular problem.
What problem is that?
> Various munging of the name or introduction of a static type keyword
> may help address this, but I'm curious if this common usage and
> what people's thoughts are.
Zope uses this all time time, I find it quite useful.
-Michel
More information about the Python-list
mailing list