Ka-Ping Yee wrote: > > On Tue, 10 Apr 2001, M.-A. Lemburg wrote: > > > What are 'distutils.sys', 'distutils.os', 'distutils.string', > > > 'distutils.re', 'distutils.distutils' doing in there? > > > (The sys.modules dictionary maps all these keys to None.) > > > > This basically means that the corresponding modules have already > > been loaded at top-level. > > But there's no 'sys' module in the distutils package. The None entry is used to cache the import miss. Please see Python/import.c for details (function mark_miss). > If there were one, it would be called 'distutils.sys' > everywhere, even within the distutils package, since > we decided that packages would always use absolute > module paths, right? > > This behaviour seems quite confusing to me: > > localhost[1]% ls -al foo > total 9 > drwxr-xr-x 2 ping users 1024 Apr 10 04:50 ./ > drwxr-xr-x 12 ping users 5120 Apr 10 04:49 ../ > -rw-r--r-- 1 ping users 0 Apr 10 04:49 __init__.py > -rw-r--r-- 1 ping users 106 Apr 10 04:50 __init__.pyc > -rw-r--r-- 1 ping users 50 Apr 10 04:50 sys.py > -rw-r--r-- 1 ping users 216 Apr 10 04:50 sys.pyc > localhost[2]% cat foo/sys.py > import sys, os > > print 'here is foo.sys' > > blah = 1 > localhost[3]% python -S > Python 2.1b2 (#28, Apr 10 2001, 02:49:05) > [GCC egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)] on linux2 > Type "copyright", "credits" or "license" for more information. > >>> import sys, foo > >>> sys.modules.keys() > ['__main__', '__builtin__', 'sys', 'foo', 'signal', 'exceptions'] > >>> import foo.sys > here is foo.sys > >>> sys.modules.keys() > ['os.path', 'os', 'foo', 'foo.sys', 'exceptions', '__main__', 'foo.os', 'posix', 'sys', '__builtin__', 'signal', 'UserDict', 'posixpath', 'stat'] > >>> sys.modules['foo.os'] > >>> sys.modules['foo.sys'] > <module 'foo.sys' from '/home/ping/python/foo/sys.py'> > >>> import foo.os > Traceback (most recent call last): > File "<stdin>", line 1, in ? > ImportError: no module named 'os' could be found > >>> import foo.sys > > At this point sys.modules['foo.sys'] is a real module, as it should > be, but sys.modules['foo.os'] is None. I don't see why 'foo.os' > should be present at all. -- Marc-Andre Lemburg ______________________________________________________________________ Company & Consulting: http://www.egenix.com/ Python Pages: http://www.lemburg.com/python/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4