Puzzling output when executing .pyc file directly

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steven D'Aprano

    #1

    Puzzling output when executing .pyc file directly

    I created a simple test file called "tester.py" :


    def dostuff(obj):
    print "Doing stuff with %s now..." % obj
    return len(str(obj))
    x = "things"
    if __name__ == "__main__":
    print dostuff(x)


    imported it into Python, then exited the current Python
    session. Then I compared the results of calling the .py
    file with those from calling the .pyc file:


    bash-2.03$ python tester.py
    Doing stuff with things now...
    6

    bash-2.03$ python tester.pyc
    Doing stuff with things now...
    6
    run_pyc_file: nested_scopes: 0


    Can anyone tell me what the run_pyc_file line is doing
    in the output of the .pyc file? Is that normal
    behaviour when calling a .pyc file?

    For my sins, I am using Python 2.1.1 on sunos5.



    Thanks,



    --
    Steven.

  • Steve Holden

    #2
    Re: Puzzling output when executing .pyc file directly

    Steven D'Aprano wrote:[color=blue]
    > I created a simple test file called "tester.py" :
    >
    >
    > def dostuff(obj):
    > print "Doing stuff with %s now..." % obj
    > return len(str(obj))
    > x = "things"
    > if __name__ == "__main__":
    > print dostuff(x)
    >
    >
    > imported it into Python, then exited the current Python
    > session. Then I compared the results of calling the .py
    > file with those from calling the .pyc file:
    >
    >
    > bash-2.03$ python tester.py
    > Doing stuff with things now...
    > 6
    >
    > bash-2.03$ python tester.pyc
    > Doing stuff with things now...
    > 6
    > run_pyc_file: nested_scopes: 0
    >
    >
    > Can anyone tell me what the run_pyc_file line is doing
    > in the output of the .pyc file? Is that normal
    > behaviour when calling a .pyc file?
    >[/color]
    No and no :-)
    [color=blue]
    > For my sins, I am using Python 2.1.1 on sunos5.
    >[/color]
    Don't know whether that was a 2.1.1-specific problem, but that's
    certainly not how 2.4.1 behaves. But then, you knew that already, didn't
    you?

    regards
    Steve
    --
    Steve Holden +44 150 684 7255 +1 800 494 3119
    Holden Web LLC www.holdenweb.com
    PyCon TX 2006 www.python.org/pycon/

    Comment

    • Peter Otten

      #3
      Re: Puzzling output when executing .pyc file directly

      Steven D'Aprano wrote:
      [color=blue]
      > bash-2.03$ python tester.pyc
      > Doing stuff with things now...
      > 6
      > run_pyc_file: nested_scopes: 0
      >
      >
      > Can anyone tell me what the run_pyc_file line is doing
      > in the output of the .pyc file? Is that normal
      > behaviour when calling a .pyc file?
      >
      > For my sins, I am using Python 2.1.1 on sunos5.[/color]

      "that's just a random debugging printf left in by mistake"



      Peter

      Comment

      Working...