星期四, 六月 21, 2007

python module name contains '.'?

sh$ mv bin.py bin.test.py
sh$ python
Python 2.3.4 (#1, Feb 6 2006, 10:38:46)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bin.test
Traceback (most recent call last):
File "", line 1, in ?
ImportError: No module named test
>>> import bin
>>> dir(bin)
['__builtins__', '__doc__', '__file__', '__name__', 'dbin', 'dbin8', 'rdbin']
>>>
".test.py" 都被忽略掉了!因为 bin.test.py 会导致查找文件 bin/test.py,当然是不存在的!

没有评论: