gpt4 book ai didi

python - '__path__' 来自哪里

转载 作者:行者123 更新时间:2023-11-28 19:59:59 24 4
gpt4 key购买 nike

我找不到谁定义了'__path__',为什么可以使用'__path__'

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_path, '__init__.py')).read()

最佳答案

您确实需要阅读一些 Python 文档并学习该语言的基础知识。

我查了一下,你好像会说中文。以下是中文 Python 文档资源:

http://www6.uniovi.es/python/doc/NonEnglish.html#chinese

现在,回答你的问题。我不确定答案是什么,所以我使用了谷歌。我在 Google 上搜索了“Python __path__”,很快就找到了:

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.

关于python - '__path__' 来自哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2003859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com