“itertools”在哪里?文件
import itertools
print itertools#ok
代码没问题,
但我找不到 itertools 文件。
谁能告诉我“itertools 文件”在哪里,
我的代码运行 python2.5
import itertools
print itertools.__file__
Traceback (most recent call last):
File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in <module>
print itertools.__file__
AttributeError: 'module' object has no attribute '__file__'
import itertools
print itertools#ok
the code is ok
but i can't find the itertools file.
who can tell me where is the 'itertools file'
my code is run python2.5
import itertools
print itertools.__file__
Traceback (most recent call last):
File "D:\zjm_code\mysite\zjmbooks\a.py", line 5, in <module>
print itertools.__file__
AttributeError: 'module' object has no attribute '__file__'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文件名以
.so
结尾意味着它是用 C 编写的扩展模块(而不是普通的 Python 模块)。如果您想查看源代码,请下载 Python 源代码并查看Modules/itertoolsmodule.c
(您也可以在浏览器中查看它:http://svn.python.org/view/python/trunk/Modules/itertoolsmodule.c?查看=日志)。编辑(作为对下面评论的回答):它也适用于 Python 2.5:
The fact that the filename ends with
.so
means it's an extension module written in C (rather than a normal Python module). If you want to take a look at the source code, download the Python source and look intoModules/itertoolsmodule.c
(you can also view it in your browser at http://svn.python.org/view/python/trunk/Modules/itertoolsmodule.c?view=log).Edit (as an answer to the comment below): it also works with Python 2.5:
对于 Windows 用户(我正在运行 Python 2.7.2,Win7x64,默认安装程序包),对 __file__ 的调用将如 @zjm1126 所指出的那样熄灭,我怀疑问题在于
itertools
是 Windows 包中的内置函数。如果您选择例外
?你会在另一个平台上得到相同的行为(例如我的 macbook 上的 Python 2.6.1) - Windows 只是碰巧有更多的内置函数,如 itertools。严格来说,这并不是一个答案,但您可以解析 sys.modules ,这会提示您它来自哪里:
它指向内置于您的 python 可执行文件中的 itertools 。
此外,imp.find_module 响应提供相同的信息:奇怪的返回元组是按规范的(请参阅:http://docs.python.org/2/library/imp.html#imp.find_module) 并告诉您该模块的类型为 6,这是
imp.C_BUILTIN
For the windows users (I'm running Python 2.7.2, Win7x64, default installer package) the call to
__file__
will flame out as @zjm1126 has noted, I suspect the problem being thatitertools
is a builtin on the windows package. If you'd picked say,exceptions
? You'd get the same behaviour on another platform (e.g. Python 2.6.1 on my macbook) - Windows just happens to have a few more builtins like itertools.It's not strictly an answer as such, but you could parse
sys.modules
which would give you a hint as to where it's coming from:which points at itertools being built-in to your python executable.
Also, the imp.find_module response is providing the same information: the weird return tuple is by spec (see: http://docs.python.org/2/library/imp.html#imp.find_module) and telling you that the module is of type 6, which is the enumeration for
imp.C_BUILTIN
试试这个
更新:
由于你的没有,另一个通过手动方式。执行 sys.path
然后根据您的系统,使用系统的搜索工具来查找它。在我的 Linux 系统上
,或者,只需在整个系统中搜索名为“itertools”的文件。
try this
update:
since yours is None, another go through a manual way. Do a sys.path
then depending on your system, use your system's search facility to find it. on my linux system
OR, just search the entire system for the file with name "itertools".