where is the '__path__' comes from
i can't find who defined the '__path__'
,why '__path__'
can be use.
import os
import sys
import warnings
import ConfigParser # ConfigParser is not a virtualenv module, so we can use it to find the stdlib
dirname = os.path.dirname
distutils_path = os.path.join(os.path.dirname(ConfigParser.__file__), 'distutils')
if os.path.normpath(distutils_path) == os.path.dirname(os.path.normpath(__file__)):
warnings.warn(
"The virtualenv distutils package at %s appears to be in the same location as the system distutils?")
else:
__path__.insert(0, distutils_path)#who defined me.???
exec open(os.path.join(distutils_p开发者_JAVA技巧ath, '__init__.py')).read()
You really need to read some Python documentation and learn the basics of the language.
I checked, and you seem to speak Chinese. Here are Python documentation resources in Chinese:
http://www6.uniovi.es/python/doc/NonEnglish.html#chinese
Now, to answer your question. I wasn't sure what the answer was, so I used Google. I did a Google search for "Python __path__
" and very quickly found:
http://docs.python.org/tutorial/modules.html
6.4.3. Packages in Multiple Directories
Packages support one more special attribute,
__path__
. This is initialized to be a list containing the name of the directory holding the package’s__init__.py
before the code in that file is executed. This variable can be modified; doing so affects future searches for modules and subpackages contained in the package.While this feature is not often needed, it can be used to extend the set of modules found in a package.
I found the following description of the __path__ variable:
It is initialized to a list of one item, containing the directory name of the package (a subdirectory of a directory on sys.path). Changing __path__ changes the list of directories that are searched for submodules of the package.
here: http://www.python.org/doc/essays/packages.html
That page discusses 'built-in package support' in Python 1.5, but it might still apply.
I can't tell you more because I don't use Python. I found this link with a Google search.
EDIT: Yes! I was going to remind you about what we discussed yesterday but a good start will be to read steveha's Chinese Python documentation.
精彩评论