python execution path

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dustin Lee

    #1

    python execution path

    I'm wondering if there is a way to get python to show each line as it
    is executed, sort of like sh -x does for shell programs. Seems like
    this would be a nice debugging aid.

    dustin
  • Peter Hansen

    #2
    Re: python execution path

    Dustin Lee wrote:[color=blue]
    > I'm wondering if there is a way to get python to show each line as it
    > is executed, sort of like sh -x does for shell programs. Seems like
    > this would be a nice debugging aid.[/color]

    The best approach, if it's really intended to be a debugging
    aid, might be to learn about "pdb", starting perhaps with the
    following line inserted shortly above where you think your
    bug might be:

    import pdb; pdb.set_trace()

    (run the code, wait for the prompt, type "?" for help, then
    read the docs ;-) )

    -Peter

    Comment

    • qhfgva@gmail.com

      #3
      Re: python execution path

      Peter Hansen wrote:[color=blue]
      > Dustin Lee wrote:[color=green]
      > > I'm wondering if there is a way to get python to show each line as[/color][/color]
      it[color=blue][color=green]
      > > is executed, sort of like sh -x does for shell programs. Seems[/color][/color]
      like[color=blue][color=green]
      > > this would be a nice debugging aid.[/color]
      >
      > The best approach, if it's really intended to be a debugging
      > aid, might be to learn about "pdb", starting perhaps with the
      > following line inserted shortly above where you think your
      > bug might be:
      >
      > import pdb; pdb.set_trace()
      >
      > (run the code, wait for the prompt, type "?" for help, then
      > read the docs ;-) )
      >
      > -Peter[/color]

      This is more of a what if-ish question I guess. I use pdb fairly
      regularly, I'm just looking to extend my debugging toolkit. I saw an
      article recently about how perl has the sh -x type functionality and I
      was curious if anything like that was possible in python. Not entirely
      sure how it would make my life better, but it seems intriguing.

      Comment

      • Peter Hansen

        #4
        Re: python execution path

        qhfgva@gmail.co m wrote:[color=blue]
        > Peter Hansen wrote:[color=green]
        >>The best approach, if it's really intended to be a debugging
        >>aid, might be to learn about "pdb" ....[/color]
        >
        > This is more of a what if-ish question I guess. I use pdb fairly
        > regularly, I'm just looking to extend my debugging toolkit. I saw an
        > article recently about how perl has the sh -x type functionality and I
        > was curious if anything like that was possible in python. Not entirely
        > sure how it would make my life better, but it seems intriguing.[/color]

        Ah. In that case, investigate sys.settrace(). There are doubtless
        a variety of recipes and snippets available in either the Cookbook
        or in the mailing list archives, after you do the basic reading in
        http://www.python.org/doc/2.4/lib/module-sys.html .

        -Peter

        Comment

        Working...