Reads a python file/module and statically analyzes it.
Project description
textpy
Reads a python file/module and statically analyzes it.
Installation
pip install textpy
Examples
Create a new file named this_is_a_file.py
:
class ThisIsAClass:
def __init__(self):
"""Write something."""
self.var_1 = "hahaha"
self.var_2 = "blabla"
def this_is_a_function(a: ThisIsAClass):
"""
Write something.
Parameters
----------
a : ThisIsAClass
An object.
"""
print(a.var_1, a.var_2)
Run the following codes to find all the occurrences of the pattern "var"
in this_is_a_file.py
:
from textpy import textpy
res = textpy("this_is_a_file.py").findall("var", styler=False)
print(res)
# Output:
# this_is_a_file.py:4: ' self.var_1 = "hahaha"'
# this_is_a_file.py:5: ' self.var_2 = "blabla"'
# this_is_a_file.py:18: ' print(a.var_1, a.var_2)'
Also, when using a Jupyter notebook, you can run a cell like this:
from textpy import textpy
textpy("this_is_a_file.py").findall("var")
and the output will be like:
Now suppose you've got a python module consists of a few files, for example, our textpy
module itself, you can do almost the same thing:
module_path = "textpy/" # you can type any path here
pattern = "note.*k" # type any regular expression here
res = textpy(module_path).findall(pattern, styler=False)
print(res)
# Output:
# textpy_local/textpy/abc.py:158: ' in a Jupyter notebook, by default True.'
# textpy_local/textpy/abc.py:375: ' in a Jupyter notebook.'
License
This project falls under the BSD 2-Clause License.
v0.1.3
- Initial release.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
textpy-0.1.3-py2.py3-none-any.whl
(11.5 kB
view hashes)
Close
Hashes for textpy-0.1.3-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f237df706f40b78dc5c27869fb32f4c277b5885e6ddda6952e4f0a77f51aa039 |
|
MD5 | da7d61ce84d21833436c953ff7c60774 |
|
BLAKE2b-256 | 0fc76c9aa8691e26743264c5dee0c670a90e89fddbf0727e99905ad6b5a37670 |