code-object

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

    #1

    code-object

    Hi, All,
    >>>code = compile('print "hello everyone, how are you? "', '<string>',
    'exec')
    >>>exec code
    hello everyone, how are you?
    >>>print code
    <code object ? at 0x8122d70, file "<string>", line 1>

    how to print the code object ?
    like the one on .pyc

    Regards
    LG


  • Gabriel Genellina

    #2
    Re: code-object

    En Tue, 20 Feb 2007 22:39:43 -0300, LG <lgoh@optonline .netescribió:
    >>>code = compile('print "hello everyone, how are you? "', '<string>',
    'exec')
    >>>exec code
    hello everyone, how are you?
    >>>print code
    <code object ? at 0x8122d70, file "<string>", line 1>
    >
    how to print the code object ?
    like the one on .pyc
    Do you want the source code back? You need a decompiler. decompyle may
    work but it's outdated.

    --
    Gabriel Genellina

    Comment

    • Steven D'Aprano

      #3
      Re: code-object

      On Tue, 20 Feb 2007 20:39:43 -0500, LG wrote:
      Hi, All,
      >
      >>>>code = compile('print "hello everyone, how are you? "', '<string>',
      'exec')
      >>>>exec code
      hello everyone, how are you?
      >>>>print code
      <code object ? at 0x8122d70, file "<string>", line 1>
      >
      how to print the code object ?
      You just did.
      like the one on .pyc
      What do you mean?

      What output do you want to see?

      Does this help?
      >>import dis
      >>code = compile("print 'hello world'", "string", "exec")
      >>dis.dis(cod e)
      1 0 LOAD_CONST 0 ('hello world')
      3 PRINT_ITEM
      4 PRINT_NEWLINE
      5 LOAD_CONST 1 (None)
      8 RETURN_VALUE



      --
      Steven D'Aprano

      Comment

      Working...