How to print python commands automatically?

Discussion in 'Python' started by Peng Yu, Nov 8, 2012.

  1. Peng Yu

    Peng Yu Guest

    Hi,

    In bash, set -v will print the command executed. For example, the
    following screen output shows that the "echo" command is printed
    automatically. Is there a similar thing in python?

    ~/linux/test/bash/man/builtin/set/-v$ cat main.sh
    #!/usr/bin/env bash

    set -v
    echo "Hello World!"
    ~/linux/test/bash/man/builtin/set/-v$ ./main.sh
    echo "Hello World!"
    Hello World!



    Regards,
    Peng
    Peng Yu, Nov 8, 2012
    #1
    1. Advertising

  2. Peng Yu

    rusi Guest

    On Nov 9, 4:12 am, Peng Yu <> wrote:
    > Hi,
    >
    > In bash, set -v will print the command executed. For example, the
    > following screen output shows that the "echo" command is printed
    > automatically. Is there a similar thing in python?
    >
    > ~/linux/test/bash/man/builtin/set/-v$ cat main.sh
    > #!/usr/bin/env bash
    >
    > set -v
    > echo "Hello World!"
    > ~/linux/test/bash/man/builtin/set/-v$ ./main.sh
    > echo "Hello World!"
    > Hello World!
    >
    > Regards,
    > Peng


    Is this what you want?
    http://docs.python.org/2/library/trace.html
    rusi, Nov 9, 2012
    #2
    1. Advertising

  3. Peng Yu

    Peng Yu Guest

    > 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()



    --
    Regards,
    Peng
    Peng Yu, Nov 9, 2012
    #3
  4. 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
    conditionsincluding 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.
    Prasad, Ramit, Nov 9, 2012
    #4
  5. Peng Yu

    Peng Yu Guest

    > 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)


    I have to explicitly specify the modules I want to ignore. Is there a
    way to ignore all the modules by default?

    ~/linux/test/python/man/library/trace/import$ cat.sh main.py main.sh test.py
    ==> main.py <==
    #!/usr/bin/env python

    import test

    test.test()


    ==> main.sh <==
    #!/usr/bin/env bash

    python -m trace --trace main.py


    ==> test.py <==
    def test1():
    print "Hello World!"

    def test():
    test1()

    ~/linux/test/python/man/library/trace/import$ python -m trace --trace
    --ignore-module=test main.py
    --- modulename: main, funcname: <module>
    main.py(3): import test
    main.py(5): test.test()
    Hello World!
    --- modulename: trace, funcname: _unsettrace
    trace.py(80): sys.settrace(None)


    --
    Regards,
    Peng
    Peng Yu, Nov 9, 2012
    #5
  6. Peng Yu

    rusi Guest

    On Nov 9, 10:41 pm, Peng Yu <> wrote:
    > I have to explicitly specify the modules I want to ignore. Is there a
    > way to ignore all the modules by default?



    Is this your problem?
    http://bugs.python.org/issue10685
    rusi, Nov 10, 2012
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Pfaff

    Re: man pages for C commands (GCC commands)

    Ben Pfaff, Jun 24, 2003, in forum: C Programming
    Replies:
    4
    Views:
    3,947
    Thomas Stegen
    Jun 28, 2003
  2. Tim Stanka
    Replies:
    1
    Views:
    785
    Jeff Epler
    Aug 2, 2004
  3. keto
    Replies:
    0
    Views:
    897
  4. Replies:
    4
    Views:
    279
    Ben Finney
    Jan 23, 2008
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    335
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page