Project organization and import

Chris Mellon arkanes at gmail.com
Tue Mar 6 14:31:38 EST 2007


On 6 Mar 2007 10:58:14 -0800, Martin Unsal <martinunsal at gmail.com> wrote:
> On Mar 6, 10:13 am, "Chris Mellon" <arka... at gmail.com> wrote:
> > You have to reload the importing module as well as the module that
> > changed. That doesn't require rewriting the import infrastructure.
>
> As far as I can tell, the moment you use "from foo_module import bar",
> you've broken reload(). Reloading higher level packages doesn't help.
> The only practical solution I can see is to rewrite __import__ and
> reload.
>

Example:

a.py
AExport = object()

b.py
from a import AExport

class Object(object): pass

BExport = Object()
BExport.a = AExport

interpreter session:

>>> import b
>>> b.AExport
<object object at 0x009804A8>
>>> b.BExport.a
<object object at 0x009804A8>
>>> import a
>>> a.AExport
<object object at 0x009804A8>
>>> "changed a.py such that AExport = list()"
'changed a.py such that AExport = list()'
>>> reload(b)
<module 'b' from 'b.pyc'>
>>> b.AExport
<object object at 0x009804A8>
>>> "note no change"
'note no change'
>>> reload(a)
<module 'a' from 'a.py'>
>>> b.AExport
<object object at 0x009804A8>
>>> "note still no change"
'note still no change'
>>> reload(b)
<module 'b' from 'b.pyc'>
>>> b.AExport
[]
>>> "now its changed"
'now its changed'
>>> b.BExport.a
[]
>>>



More information about the Python-list mailing list