[PYTHON] Checking methods and variables using the library see

Introducing the Python library see

see is useful because it is useful when checking methods and variables in the library. This is useful when you want to check if all the methods are included when you add a new library, or when you want to check what variables the class has.

How to use

I will omit the introduction method because I think that it will come out soon if I check it. Basically, I use it on terminal (Mac OSX, Yosemite) without writing it in a script. Click here for the source https://github.com/araile/see/blob/develop/see.py

check.


$ python 
Python 2.7.10 (default, Jul 14 2015, 19:46:27) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import see
>>> see.see(see)
    help()           .PY_300          .PY_301          .SYMBOLS         .SeeError()
    .fcntl           .fn_filter()     .fnmatch         .inspect         .line_width()
    .re              .regex_filter()  .see()           .struct          .sys
    .term_width()    .termios         .textwrap

Like this, you can easily check what is in the library. If you look at the output, you can see that it uses a standard library such as .re .fnmatch .sys. Those with () are methods, and those without () are variables, so it is very easy to understand. It would be better if there was argument information etc ...

Frequently used functions in library see

My personal favorites are .fn_filter () and .regex_filter (). fn_filter (names, pat) simply puts an iteration in the first argument and a pattern in the second argument. If you normally put see.see (see) in the first argument, the above output will be passed. The second argument is a regular expression used in ShellScript? If you put in, the one that matches the pattern will be returned as a tuple.

By the way, fn in fn_filter means fnmatch. So, as the name suggests, this function just applies filter with fnmatch. Below is a simple example. The first is a variable and the second is a function only. The one with . at the beginning is included becauserepr ()and+are mixed depending on the library.

test_fn_filter.


>>> see.fn_filter(see.see(see), '.*[0-9a-zA-Z]')
('.PY_300', '.PY_301', '.SYMBOLS', '.fcntl', '.fnmatch', '.inspect', '.re', '.struct', '.sys', '.termios', '.textwrap')
>>> see.fn_filter(see.see(see), '.*)')
('.SeeError()', '.fn_filter()', '.line_width()', '.regex_filter()', '.see()', '.term_width()')

Then regex_filter () Again, as the name suggests, regex is a regular expression. Apply filter with re.match in the standard library re and output as a tuple. So, the first argument is the same as fn_filter, and thesecond argument is a regular expression. Basically, it is used in the same way asfn_filter`, so the explanation is omitted.

Use properly

Personally, I use fn_filter when I want to see functions and variables, and regex_filter when I want to find something that contains a certain string.

You can see what I didn't explain by looking at the source code.

Recommended Posts

Checking methods and variables using the library see
Example of using class variables and class methods
Tokenize using the Hugging Face library
[python] Checking the memory consumption of variables
[Python] A program that finds the minimum and maximum values without using methods
I checked the library for using the Gracenote API
Aggregate test results using the QualityForward Python library
Solve the knapsack problem using pyomo and glpk
Organize the meaning of methods, classes and objects
Response the resized image using Flask and PILImage
Using the 3D plot library MayaVi from Julia
I tried using the functional programming library toolz
Understand the TensorFlow namespace and master shared variables
I installed and used the Deep Learning library Chainer
Creating a graph using the plotly button and slider
Evaluate and concatenate strings in variables using eval in bash
Send and receive Gmail via the Gmail API using Python
Select the required variables in TensorFlow and save / restore
Part 1 Running e-Gov using the SmartHR library kiji (e-Gov specifications)
Using the National Diet Library Search API in Python