PyScribe is a library for easier print debugging of python in case of trouble.
You can install it with pip.
$ pip install pyscribe
Call and execute the pyscribe API in the program to be debugged.
$ pyscribe do_something.py
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 | 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 |
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
########################################
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.
Recommended Posts