[Python-Dev] Draft PEP: "Simplified Package Layout and Partitioning"

P.J. Eby pje at telecommunity.com
Fri Jul 22 04:05:22 CEST 2011


At 03:04 AM 7/22/2011 +0200, Antoine Pitrou wrote:
>The additional confusion lies in the fact that a module can be 
>shadowed by something which is not a module (a mere global 
>variable). I find it rather baffling.

If you move x.py to x/__init__.py, it does *exactly the same thing* 
in current versions of Python:

Python 2.7.1 (r271:86832, Nov 27 2010, 18:30:46) [MSC v.1500 32 bit 
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
 >>> from x import y
 >>> import x.y
 >>> x.y
<module 'x.y' from 'x\y.py'>
 >>> y
5

The PEP does nothing new or different here.  If something is baffling 
you, it's the behavior of "from ... import", not the actual importing process.

"from x import y" means "import x; y = x.y".  The PEP does not 
propose we change this.  ;-)



More information about the Python-Dev mailing list