Replace a module variable with a function call

Carsten Haese carsten at uniqsys.com
Mon Feb 6 14:59:10 EST 2006


On Mon, 2006-02-06 at 14:38, gabriel.becedillas at gmail.com wrote:
> Your post didn't provide any help at all, it was a useless sarcastic
> post and I'm a very sensible person.

Your original question didn't provide enough detail to offer an answer,
which is why I asked the question what the dynamic return value should
depend on. I am sorry if my conjecture that the return value might
depend on the phase of the moon offended you, but my post was not meant
to be useless. It was a necessary follow-up question because you didn't
define your requirements clearly enough.

If the condition upon which the return value is determined can be
evaluated at import time and doesn't change henceforth, a simple if
statement in the module will serve your need.

If the value *really* needs to be re-evaluated every time the name is
looked up, you'll need to follow the advice that Tim Hochberg has
already given on this thread. Note, though, that that won't prevent the
user code from caching the return value and circumventing the
re-evaluation.

-Carsten





More information about the Python-list mailing list