Skip to main content

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


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.4-py2.py3-none-any.whl (25.7 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page