查找Python模块的源代码 [英] Finding the source code for a Python module

查看:195
本文介绍了查找Python模块的源代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PyCharm作为我的编辑器,而且看来某些子目录模块,即numpy.random.normal.不要灰心,我追踪了numpy.random住到/usr/lib/python2.7/dist-packages/numpy/random的位置.

I'm using PyCharm as my editor and seemingly it doesn't behave well with certain sub-modules namely numpy.random.normal. Not to be disheartened I tracked down where numpy.random lives to /usr/lib/python2.7/dist-packages/numpy/random.

我看不到任何正常情况.在__init__.py中有它的定义,但没有实际代码可供我复制到项目的新类中.

I can't see any instance of normal. There's the definition for it in __init__.py but no actual code for me to copy into a new class for my project.

我在错误的位置输入代码了吗?

Am I looking in the wrong place for the code?

推荐答案

您可以这样做来找出包所在的位置:

You can find out, where a package is located by doing so:

import numpy.random
print numpy.random.__file__

在您的情况下,该模块的主要部分似乎是用C实现的.您可以在目录中看到其中有一个文件"mtrand.so".这是从C源创建的共享对象,这些源通常不随运行时程序包一起提供.导入模块/包时,Python系统可以在运行时加载此类共享库.

In your case, it seems that the main parts of the module are implemented in C. You can see in the directory, that there is a file "mtrand.so" located in it. This is a shared object that was created from C sources, which are typically not delivered with the runtime package. The Python system can load such shared objects at runtime, when you import the module/package.

这篇关于查找Python模块的源代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆