[PYTHON] Print debug with PyScribe

What is PyScribe

PyScribe is a library for easier print debugging of python in case of trouble.

Installation method

You can install it with pip.

$ pip install pyscribe

How to use

Call and execute the pyscribe API in the program to be debugged.

command

$ pyscribe do_something.py

Runtime options

Command arguments Contents
--extraargs Pass runtime arguments to the calling program
--clean File with parts related to pyscribe removed({name}_clean.py)Output
--desugared Convert from pyscribe format to format that conforms to python's standard API
--log Run-time log file(pyscribe_logs.txt)Output
--nolines Hide line numbers

API call

API call Contents
pyscribe.Scriber(labels=[]) Initialization of pyscribe
pyscribe.p(object, label=None) Output the value of the object in a format that matches the type
pyscribe.iterscribe(object) Outputs the current value of the iterator in a for or while loop
pyscribe.watch(object) Output when the value of the specified object changes
pyscribe.d(object, unit="*") Outputs the character specified by unit as a delimiter

Example

pyscribe_sample.py


from pyscribe import pyscribe

def main():
    ps = pyscribe.Scriber()

    x = "hogehoge"
    ps.p(x)

    y = "hello"
    ps.p(y)
    ps.watch(y)
    y = "world"
    y = "!!"

    z = 1234
    ps.d(z, unit="#")


if __name__ == "__main__":
    main()

--Execute

$ pyscribe pyscribe_sample.py

--Result

From line 7: x is the str hogehoge
From line 10: y is the str hello
From line 11: Watching variable y, currently str hello
From line 12: y changed to world
From line 13: y changed to !!
From line 16:
########################################
z is the int 1234
########################################

in conclusion

It's a simple library, but it may make print debugging easier in case of trouble. Personally, I thought it would be useful to use the watch command, which can monitor changes in the value of a given object.

reference

pyscribe - github

Recommended Posts

Print debug with PyScribe
Debug Python with VS Code
Debug with PEPPER python interpreter
Prevent omissions with pandas print
Debug shared libraries with VScode
Debug email sending with Python's smtpd.DebuggingServer
Print with python3 without line breaks
Debug python multiprocess program with VSCode
I want to debug with Python
Print memos with a receipt printer (serialization)