Easy way to check the source of Python modules

https://github.com/trsqxyz/prins

Usage

>>> import prins
>>> p = prins.prins()
>>> p.dropto('this', 'prins', 'spam')
Not Found spam.

I found that ʻimp.find_module () opens the source file with read, so I wanted to know it and wanted to write it to a text file at once. Arguments that are not passed as a character string are converted to a character string, but if ʻimport is done, they will not be searched properly. I think it will be useful when you know the standard module

Prins stands for Print source

2014-08-24 10:46 Addendum

I received a comment.

When searching for a standard module, you may start a pydoc server with pydoc -p 8080.

I was able to browse the Python 3.x documentation with pydoc -p 8080 and then b with Python 2.x pydoc3 -p 8080. Very convenient

Also, if you want to know information about modules like this article, the inspect package is useful. For example

import re
import inspect

print(inspect.getsourcefile(re)) #Get file path
print("".join(inspect.findsource(re)[0])) #Get the contents of the file

I thought this method would be smart when checking at a terminal. However, there were ʻinspect.filesource () and ʻinspect.getsource (), so I examined the difference.

>>> import re
>>> import inspect
>>> type(inspect.getsource(re))
<class 'str'>
>>> type(inspect.findsource(re))
<class 'tuple'>

So you can also check it with print (inspect.getsource (re)). @podhmo Thank you.

Recommended Posts

Easy way to check the source of Python modules
Easy way to customize Python import
PyArmor ~ Easy way to encrypt and deliver python source code ~
Get the source of the page to load infinitely with python.
An easy way to pad the number with zeros depending on the number of digits [Python]
An easy way to hit the Amazon Product API in Python
Check the behavior of destructor in Python
Easy way to round off to the nearest whole number with python3
How to check the version of Django
Check the existence of the file with python
How to check the memory size of a variable in Python
How to check the memory size of a dictionary in Python
Easy way to use Wikipedia in Python
Check the path of the Python imported module
Python> sys.path> List of strings indicating the path to search for modules
(Python Selenium) I want to check the settings of the download destination of WebDriver
I made a program to check the size of a file in Python
The fastest way for beginners to master Python
[Python] Read the source code of Bottle Part 2
[python] Check the elements of the list all, any
Easy way to use Python 2.7 on Cent OS 6
The easiest way to synthesize speech with python
Check the date of the flag duty with Python
[Python] Read the source code of Bottle Part 1
Excel X Python The fastest way to work
The easiest way to use OpenCV with python
Introduction to Python with Atom (on the way)
An easy way to call Java from Python
List of python modules
the zen of Python
python beginners tried to predict the number of criminals
The wall of changing the Django service from Python 2.7 to Python 3
Template of python script to read the contents of the file
How to get the number of digits in Python
[python] option to turn off the output of click.progressbar
Easy way to scrape with python using Google Colab
[Python] Summary of how to specify the color of the figure
14 quizzes to understand the surprisingly confusing scope of Python
[Introduction to Python] Basic usage of the library matplotlib
To do the equivalent of Ruby's ObjectSpace._id2ref in Python
Check the asymptotic nature of the probability distribution in Python
Completely translated the site of "The Hitchhiker's Guide to Python"
Python Note: The mystery of assigning a variable to a variable
I tried to summarize the string operations of Python
An easy way to measure the processing speed of a disk recognized by Linux
How to check in Python if one of the elements of a list is in another list
Towards the retirement of Python2
Python --Check type of values
About the ease of Python
Check OpenSSL version of python 2.6
[Python] Another way to import
Easy way to rename files
About the features of Python
Source installation and installation of Python
[Python] Check the installed libraries
I downloaded the python source
The Power of Pandas: Python
I tried to find the entropy of the image with python
[Python] Change the Cache-Control of the object uploaded to Cloud Storage
Try to get the function list of Python> os package
[python] How to check if the Key exists in the dictionary