[Zope3-dev] Importing
Jeffrey P Shell
jeffrey@cuemedia.com
Wed, 12 Dec 2001 10:15:14 -0700
I'm getting a little confused about what we're all talking about
here, so I'm going to try to fill in a real example based on what
I'm working on today.
I have a fairly rich CMF based product (CMF chosen for it's
component-model-like features more than any need for actual content
management features). As I noticed that the amount of modules was
increasing dramatically, I broke the product out into sub-packages:
myproduct/base
myproduct/content
myproduct/interfaces
myproduct/tools
myproduct/workflow
base has some common base clases, so an import in
content/contact.py looks like:
from Products.myproduct.base import FolderyContent
^^^^^^^^
I interpreted Chris Withers' original question to be about - what
happens if that lead "Products" goes away? It's something we're
well used to having around. How am I supposed to reference
associated subpackages if it's not there? Am I designing my code
poorly? Am I missing out on some undocumented __magic__
variable/attribute? Or am I just confused about where this
discussion has been / is going?
On Wednesday, December 12, 2001, at 05:49 AM, Guido van Rossum wrote:
[SNIP]
>> well, if i have:
>>
>> /package1/
>> /package1/package2a/modulea
>> /package1/package2a/package2b/mobuleb
>>
>> ...then when package 2 is being used on its own, I could do the
>> following in
>> moduleb:
>
> What do you mean by "on its own?". I'm afraid that you mean that
> /package1 is on sys.path? That's evil!
>
>> from package2a.modulea import someclass
>>
>> However, as soon as package2a is installed as a sub-package of
>> package1, then
>> I'd have to change that import statement to:
>>
>> from package1.package2a.modulea import someclass
>>
>> ...or am I missign something?
>
> No, we just disagree on the desirability of all this. I think
> "fixing" this in Python would be wrong, and leading to more confusion
> (for the *reader*, it's hard enough to figure out where to look for
> modules without multiple levels of relative import). But others have
> occasionally asked for this too. We should make it a PEP and reject
> it for clarity. (PEP 667 anyone?)
>
> --Guido van Rossum (home page: http://www.python.org/~guido/)
>
> _______________________________________________
> Zope3-dev mailing list
> Zope3-dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope3-dev
>
Jeffrey P Shell, jeffrey@cuemedia.com