Django Book 翻译
菜单>:
TOC
返回
原文:
For example, lets say your Python path is set to ``['', '/usr/lib/python2.4/site-packages', '/home/username/djcode/']`` . If you execute the Python code ``from foo import bar`` , Python will first check for a module called ``foo.py`` in the current directory. (The first entry in the Python path, an empty string, means the current directory.) If that file doesnt exist, Python will look for the file ``/usr/lib/python2.4/site-packages/foo.py`` . If that file doesnt exist, it will try ``/home/username/djcode/foo.py`` . Finally, if *that* file doesnt exist, it will raise ``ImportError`` .
翻译:
举例来说,假定你将 Python 路径设置为 ``['','/usr/lib/python2.4/site-packages','/home/username/djcode/']`` 。如果执行代码 ``from foo import bar`` ,Python 将会首先在当前目录查找 ``foo.py`` 模块( Python 路径第一项的空字符串表示当前目录)。如果文件不存在,Python将查找 ``/usr/lib/python2.4/site-packages/foo.py`` 文件。如果文件也不存在,它将尝试 ``/home/username/djcode/foo.py`` 。最后,如果 *这个* 文件还不存在,它将引发 ``ImportError`` 异常。
备注:
译者: