When testing or creating a new function, I often like to print every line of code that is happening so that I can see how every line is processing.
Is there a way that can serve this purpose? I'm looking for something more convenient so I don't have to type print after every line.
For example, instead of writing this function
def test_func():
l = range(10)
print l
l = zip(l,range(30,40))
print l
l = dict(l)
print l
I'd like to write this without writing print, yet still get every line printed
def test_func():
l = range(10)
l = zip(l,range(30,40))
l = dict(l)
Perhaps I can use a Python decorator or something for this?
So, if you want to "add" a period/dot/full stop to the end of your string, you can do this: flavors = ["chocolate", "mint", "strawberry"] ". ".
It is used to indicate the end of a line of text. You can print strings without adding a new line with end = <character> , which <character> is the character that will be used to separate the lines.
"\n" can be used for a new line character, or if you are printing the same thing multiple times then a for loop should be used.
You'd better use debugger for that purpose. But if you want to print each line you can run program with 'trace`.
python -m trace --trace asd.py
--- modulename: asd, funcname: <module>
asd.py(1): def test_func():
asd.py(6): test_func();
--- modulename: asd, funcname: test_func
asd.py(2): l = range(10)
asd.py(3): l = zip(l,range(30,40))
asd.py(4): l = dict(l)
--- modulename: trace, funcname: _unsettrace
trace.py(80): sys.settrace(None)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With