How to print python commands automatically?

Prasad, Ramit ramit.prasad at jpmorgan.com
Fri Nov 9 16:26:08 EST 2012


Peng Yu wrote:
> 
> > Is this what you want?
> > http://docs.python.org/2/library/trace.html
> 
> I'm not able to get the mixing of the python command screen output on
> stdout. Is there a combination of options for this purpose?
> 
> ~/linux/test/python/man/library/trace$ cat main1.py
> #!/usr/bin/env python
> 
> def f():
>   print "Hello World!"
> 
> f()
> ~/linux/test/python/man/library/trace$ cat main.sh
> #!/usr/bin/env bash
> 
> python -m trace --count -C . main1.py -t
> 
> ~/linux/test/python/man/library/trace$ ./main.sh
> Hello World!
> ~/linux/test/python/man/library/trace$ cat main1.cover
>        #!/usr/bin/env python
> 
>     1: def f():
>     1:   print "Hello World!"
> 
>     1: f()
> 

Try with just --trace?


C:\ramit>python.exe -m trace test.py
C:\ramit\Python27\lib\trace.py: must specify one of --trace, --count, --report, --listfuncs, or --trackcalls

C:\ramit>python -m trace --trace test.py
 --- modulename: test, funcname: <module>
test.py(2): def f():
test.py(5): f()
 --- modulename: test, funcname: f
test.py(3):     print "Hello World!"
Hello World!
 --- modulename: trace, funcname: _unsettrace
trace.py(80):         sys.settrace(None)



~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  



More information about the Python-list mailing list