我如何了解一个给定的Python模块的源文件安装在哪里?Windows上的方法和Linux上的方法不同吗?

我特别试图寻找datetime模块的源代码,但我对更一般的答案也感兴趣。


当前回答

Python 3.2中的新功能,你现在可以使用dis模块中的code_info(): http://docs.python.org/dev/whatsnew/3.2.html#dis

其他回答

并非所有的python模块都是用python编写的。Datetime恰好是其中之一,并且(在linux上)是Datetime。

你必须将源代码下载到python标准库才能得到它。

看看这个漂亮的"cdp"命令,cd到包含指定Python模块源代码的目录:

cdp () {
  cd "$(python -c "import os.path as _, ${1}; \
    print _.dirname(_.realpath(${1}.__file__[:-1]))"
  )"
}

如上所述 在python中只使用help(模块) 即

进口分数

帮助(分数)

如果你的模块,在例子中的分数,被安装,然后它会告诉你的位置和有关它的信息,如果它没有安装,它说模块不可用

如果它不可用,默认情况下python不会附带,在这种情况下,你可以检查你在哪里找到它的下载信息

Python 3.2中的新功能,你现在可以使用dis模块中的code_info(): http://docs.python.org/dev/whatsnew/3.2.html#dis

在python解释器中,您可以导入特定的模块,然后键入help(module)。这将提供诸如名称、文件、模块文档、描述等详细信息。

Ex:

import os

help(os)


Help on module os:

NAME

os - OS routines for Mac, NT, or Posix depending on what system we're on.

FILE

/usr/lib/python2.6/os.py

MODULE DOCS

http://docs.python.org/library/os

DESCRIPTION

This exports:

- all functions from posix, nt, os2, or ce, e.g. unlink, stat, etc.

- os.path is one of the modules posixpath, or ntpath

- os.name is 'posix', 'nt', 'os2', 'ce' or 'riscos'

等人