make order of function definitions irrelevant
anton muhin
antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru
Mon Nov 10 14:39:19 EST 2003
Joerg Schuster wrote:
> Hello,
>
> according to
>
> http://mail.python.org/pipermail/tutor/2001-July/007246.html
>
> the order of function definitions does matter in python. Does anyone
> know a trick to avoid this? Is there a way to "declare" functions
> without defining them?
>
> (Making the order of function definitions irrelevant would be useful
> for automatically generated python scripts.)
>
>
> Jörg
>
>
As was said, you usually don't need such a thing. If you desperatly
looking for it, something like this might work:
func = None
def caller():
assert func, 'func is None'
return func()
def foo():
return 'foo'
def bar():
return 'bar'
func = foo
print func()
Of course, in this case you'd better pass an actual function as a
parameter. But, again, almost for sureit's a flaw in your design.
regards,
anton.
More information about the Python-list
mailing list