Package: textpy
textpyReads a python file/module and statically analyzes it. This works well with Jupyter extensions in VScode, and have better performance when the file/module is formatted withPEP-8.Installation$pipinstalltextpyRequirementslazyr>=0.0.11
pandas>=1.4.0 # A lower version is also acceptable, but some features will be invalidExamplesCreate a new file namedmyfile.pyunder./examples/(or any dir, just for an example):#!/usr/bin/env python# -*- coding: utf-8 -*-fromtypingimport*classMyClass:def__init__(self):"""Write something."""self.var_1="hahaha"self.var_2="blabla"defprint_my_class(a:MyClass):"""Print something.Parameters----------a : ThisIsAClassAn object."""print(a.var_1,a.var_2)Run the following codes to find all the occurrences of the pattern "va" inmyfile.py:>>>fromtextpyimporttextpy>>>res=textpy("./examples/myfile.py").findall("va",styler=False)>>>resexamples/myfile.py:10:'        self.var_1 = "hahaha"'examples/myfile.py:11:'        self.var_2 = "blabla"'examples/myfile.py:24:'    print(a.var_1, a.var_2)'Also, when using a Jupyter notebook in VScode, you can run a cell like this:>>>fromtextpyimporttextpy>>>textpy("./examples/myfile.py").findall("va")and the output will be like:sourcematchmyfile.MyClass.__init__:10self.var_1 = "hahaha"myfile.MyClass.__init__:11self.var_2 = "blabla"myfile.print_my_class:24print(a.var_1, a.var_2)Note that in the Jupyter notebook case, the matched substrings are **clickable**, linking to where the patterns were found.Now suppose you've got a python module consists of a few files, for example, ourtextpymodule 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("note.*k",styler=False,line_numbers=False)>>>restextpy/abc.py:'            in a Jupyter notebook, this only takes effect when'textpy/abc.py:'        in a Jupyter notebook.'textpy/__init__.py:'Also, when using a Jupyter notebook in VScode, you can run a cell like this:'textpy/__init__.py:'Note that in the Jupyter notebook case, the matched substrings are **clickable**, linking to where'textpy/__init__.py:'>>> pattern = "note.*k" # type any regular expression here'textpy/__init__.py:'>>> res = textpy(module_path).findall("note.*k", styler=False, line_numbers=False)'See AlsoGithub repositoryhttps://github.com/Chitaoji/textpy/PyPI projecthttps://pypi.org/project/textpy/LicenseThis project falls under the BSD 3-Clause License.Historyv0.1.21Various improvements.v0.1.20Fixed issues:Incorrectly displayed file paths in the output ofTextPy.findall(styler=False);Expired file links in the output ofTextPy.findall(styler=True, line_numbers=False).v0.1.19Various improvements.v0.1.18Updated LICENSE.v0.1.17Refactored README.v0.1.16Lazily importedpandasto reduce the time cost for importing.v0.1.12New optional parameters forTextPy.findall():whole_word: whether to match whole words only;case_sensitive: specifies case sensitivity.v0.1.10New optional parameter fortextpy():encoding: specifies encoding.v0.1.9Removing unnecessary dependencies.v0.1.8Bugfix for Windows.v0.1.5Compatible withpandasversions lower than 1.4.0.Updatedtextpy():Pathobjects are now acceptable as parameters.New optional parameterhometo specify the home path.More flexible presentation of output fromTextPy.findall().v0.1.4Fixed a display problem of README on PyPI.v0.1.3Initial release.