Module Structure/Import Design Problem

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Nov 20 22:59:00 EST 2008


En Thu, 20 Nov 2008 17:36:11 -0200, Stef Mientki <stef.mientki at gmail.com>  
escribió:

>>> I'm not an expert, I even don't fully understand your problem,
>>> but having struggled with imports in the past,
>>> I've a solution now, which seems to work quit well.
>>>
>> That's not very helpful, is it? Were you planning to keep the solution
>> secret?
>>
> sorry slip of the keyboard ;-)
> http://mientki.ruhosting.nl/data_www/pylab_works/pw_importing.html

May I reiterate my criticism to your "solution" posted last week?
I don't think extending sys.path to include every directory under your  
project is a good idea. Basically, you're flattening the directory layout,  
removing any structure, like it was before Python 1.5 added package  
support.
It is like dumping all your modules in a single directory, with no  
hierarchy and lots of name conflicts.
Worse: because your proposal makes the same file reachable under many  
different names, the *same* source module will generate *different* module  
objects stored as *different* entries in sys.modules. Globals don't work  
anymore, subclasses aren't subclasses... lots of problems.
Relative imports (PEP328 [1]) were introduced -among other things- as an  
attempt to avoid such problems. You're going in the opposite direction.  
Please stop doing that - or at least keep us informed of where you work!

[1] http://www.python.org/dev/peps/pep-0328

-- 
Gabriel Genellina




More information about the Python-list mailing list