[Python-bugs-list] [ python-Bugs-493628 ] import not pythonic in 2.1.1
noreply@sourceforge.net
noreply@sourceforge.net
Sat, 15 Dec 2001 09:46:20 -0800
Bugs item #493628, was opened at 2001-12-15 03:37
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=493628&group_id=5470
Category: Python Interpreter Core
Group: Not a Bug
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Chris Withers (fresh)
Assigned to: Nobody/Anonymous (nobody)
Summary: import not pythonic in 2.1.1
Initial Comment:
Take a package 'aPackage', which contains a sub-package 'aSubPackage' that in turn contains a
module 'aModule' that defines a class 'aClass'.
If I do:
import aPackage.aSubPackage
print aPackage.aSubPackage.aModule
I get:
Traceback (most recent call last):
File "x.py", line xx, in ?
print aPackage.aSubPackage.aModule
AttributeError: 'aPackage.aSubPackage' module has no attribute 'aModule'
A yet, if I do:
import aPackage.aSubPackage.aModule
print aPackage.aSubPackage.aModule
I get:
<module 'aPackage.aSubPackage.aModule' from 'some_path'>
...as expected, which is very confusing and doesn't feel 'right' :-S
----------------------------------------------------------------------
>Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-15 09:46
Message:
Logged In: YES
user_id=6380
http://www.python.org/doc/essays/packages.html
----------------------------------------------------------------------
Comment By: Chris Withers (fresh)
Date: 2001-12-15 09:15
Message:
Logged In: YES
user_id=24723
Okay, if it's intended, that means there's a good reason for it...
...where can I look for enlightenment as to what that is?
cheers,
Chris
----------------------------------------------------------------------
Comment By: Guido van Rossum (gvanrossum)
Date: 2001-12-15 07:39
Message:
Logged In: YES
user_id=6380
Better adjust your intuition. :-)
This is as intended. Attributes of packages that are
*modules* are only loaded when the corresponding module is
explicitly imported (by you, or by some other code, e.g. the
package's __init__.py).
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=493628&group_id=5470