繁体   English   中英

如何查看 python 库的源代码?

[英]How can I see the source code for a python library?

我目前发现自己在 python 中经常使用 bs4/BeautifulSoup 库,并且最近一直想知道它是如何工作的。 我很想看看这个库的源代码,但不知道怎么做。 有谁知道如何做到这一点? 谢谢。

第一步是询问模块本身。 通常它就是你所需要的

>>> import bs4
>>> bs4.__file__
'/home/td/anaconda3/lib/python3.7/site-packages/bs4/__init__.py'
>>> exit()
$ pushd /home/td/anaconda3/lib/python3.7/site-packages/bs4
$ ls
builder    diagnose.py  __init__.py  testing.py
dammit.py  element.py   __pycache__  tests

如果您使用任何 IDE,您可以右键单击导入的行并转到实施。 否则,您可以在<python_installtion_path>\Lib\site-packages目录中找到源代码。

Go to the location where python is installed and inside the python folder, you will have a folder called Lib you can find all the packages there open the required python file you will get the code.

示例位置:C:\Python38\Lib

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM