CONSTRUCT - Python's way of Ruby's "alias_method"
Maric Michaud
maric at aristote.info
Sat Jun 10 06:45:19 EDT 2006
Le Vendredi 09 Juin 2006 20:06, Ilias Lazaridis a écrit :
> the code below works, but has the limitation that I cannot import the
> syncdb_hook within "django.core.management".
In [4]: from b import CONS
In [5]: import b
In [6]: b.CONS = 3
In [7]: CONS
Out[7]: 5
In [8]: from b import CONS
In [9]: CONS
Out[9]: 3
So, if you change one module name, a function or a class or a constant, you
must do it before it is imported, or you must reload modules using it. But
either are not always possible, and the later is not what you want to achieve
here as it will re-execute all initialisation code in those modules.
But think of that, a function is hopefully an object in python, hmmm :
In [1]: from temp import func
In [2]: func(5)
Out[2]: 5
In [3]: def g(s) : return s*2
...:
In [4]: func.func_code = g.func_code
In [5]: func(5)
Out[5]: 10
hey, that should work !
--
_____________
Maric Michaud
_____________
Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097
More information about the Python-list
mailing list