Exploring code objectsFactorisation code running slowDumping fields from Python objectsBuilding Data abstraction for line segments using “objects”HackerRank “Lists” codeGeneric number class codeFirst-class objects in PythonDownset calculation codeWrite/read efficiently dataframe objects into memory or diskTell Me More Effecient Way For This CodePython code issues

Why "Having chlorophyll without photosynthesis is actually very dangerous" and "like living with a bomb"?

Rock identification in KY

Should the isomorphism theorems be seen as an "interface" between algebra and category theory?

Today is the Center

Theorems that impeded progress

Is it unprofessional to ask if a job posting on GlassDoor is real?

Alternative to sending password over mail?

Revoked SSL certificate

A newer friend of my brother's gave him a load of baseball cards that are supposedly extremely valuable. Is this a scam?

What's that red-plus icon near a text?

Do infinite dimensional systems make sense?

How do I deal with an unproductive colleague in a small company?

Paid for article while in US on F1 visa?

What does it mean to describe someone as a butt steak?

Was any UN Security Council vote triple-vetoed?

Arithmetic with LuaLaTeX

I'm flying to France today and my passport expires in less than 2 months

dbcc cleantable batch size explanation

"You are your self first supporter", a more proper way to say it

Maximum likelihood parameters deviate from posterior distributions

Replacing matching entries in one column of a file by another column from a different file

Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)

How to regain access to running applications after accidentally zapping X.org?

Operational amplifier as a comparator at high frequency



Exploring code objects


Factorisation code running slowDumping fields from Python objectsBuilding Data abstraction for line segments using “objects”HackerRank “Lists” codeGeneric number class codeFirst-class objects in PythonDownset calculation codeWrite/read efficiently dataframe objects into memory or diskTell Me More Effecient Way For This CodePython code issues






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1












$begingroup$


I am reading the book: "Obi Ike-Nwosu. Inside The Python Virtual Machine" and have reached the "Code Objects" chapter. This chapter has all code object fields printed out:



co_argcount = 1
co_cellvars = ()
co_code = b'|x00dx01x16x00dx02kx02rx1e|x00dx03x16x00dx02kx02rx1ed\
x04Sx00n,|x00dx01x16x00dx02kx02r0dx05Sx00nx1a|x00dx03x16x00dx02kx02r
Bdx06Sx00nx08tx00|x00x83x01Sx00dx00Sx00'
co_consts = (None, 3, 0, 5, 'FizzBuzz', 'Fizz', 'Buzz')
co_filename = /Users/c4obi/projects/python_source/cpython/fizzbuzz.py
co_firstlineno = 6
co_flags = 67
etc...


but there is no explanation how this can be done programatically, so I wrote my own code:



# Making the code object for 'my_add' function
code_obj = compile('my_add', os.path.realpath(__file__), 'exec')

# Iterating through all instance attributes
# and calling all having the 'co_' prefix
for name in dir(code_obj):
if name.startswith('co_'):
co_field = getattr(code_obj, name)
print(f'name:<20 = co_field')


Output



co_argcount = 0
co_cellvars = ()
co_code = b'ex00x01x00dx00Sx00'
co_consts = (None,)
co_filename = /home/minimax/learning_python/oop/source.py
co_firstlineno = 1
co_flags = 64
co_freevars = ()
co_kwonlyargcount = 0
co_lnotab = b''
co_name = <module>
co_names = ('my_add',)
co_nlocals = 0
co_stacksize = 1
co_varnames = ()


Question: Have I used the optimal way? How would you solve this problem?










share|improve this question









$endgroup$


















    -1












    $begingroup$


    I am reading the book: "Obi Ike-Nwosu. Inside The Python Virtual Machine" and have reached the "Code Objects" chapter. This chapter has all code object fields printed out:



    co_argcount = 1
    co_cellvars = ()
    co_code = b'|x00dx01x16x00dx02kx02rx1e|x00dx03x16x00dx02kx02rx1ed\
    x04Sx00n,|x00dx01x16x00dx02kx02r0dx05Sx00nx1a|x00dx03x16x00dx02kx02r
    Bdx06Sx00nx08tx00|x00x83x01Sx00dx00Sx00'
    co_consts = (None, 3, 0, 5, 'FizzBuzz', 'Fizz', 'Buzz')
    co_filename = /Users/c4obi/projects/python_source/cpython/fizzbuzz.py
    co_firstlineno = 6
    co_flags = 67
    etc...


    but there is no explanation how this can be done programatically, so I wrote my own code:



    # Making the code object for 'my_add' function
    code_obj = compile('my_add', os.path.realpath(__file__), 'exec')

    # Iterating through all instance attributes
    # and calling all having the 'co_' prefix
    for name in dir(code_obj):
    if name.startswith('co_'):
    co_field = getattr(code_obj, name)
    print(f'name:<20 = co_field')


    Output



    co_argcount = 0
    co_cellvars = ()
    co_code = b'ex00x01x00dx00Sx00'
    co_consts = (None,)
    co_filename = /home/minimax/learning_python/oop/source.py
    co_firstlineno = 1
    co_flags = 64
    co_freevars = ()
    co_kwonlyargcount = 0
    co_lnotab = b''
    co_name = <module>
    co_names = ('my_add',)
    co_nlocals = 0
    co_stacksize = 1
    co_varnames = ()


    Question: Have I used the optimal way? How would you solve this problem?










    share|improve this question









    $endgroup$














      -1












      -1








      -1





      $begingroup$


      I am reading the book: "Obi Ike-Nwosu. Inside The Python Virtual Machine" and have reached the "Code Objects" chapter. This chapter has all code object fields printed out:



      co_argcount = 1
      co_cellvars = ()
      co_code = b'|x00dx01x16x00dx02kx02rx1e|x00dx03x16x00dx02kx02rx1ed\
      x04Sx00n,|x00dx01x16x00dx02kx02r0dx05Sx00nx1a|x00dx03x16x00dx02kx02r
      Bdx06Sx00nx08tx00|x00x83x01Sx00dx00Sx00'
      co_consts = (None, 3, 0, 5, 'FizzBuzz', 'Fizz', 'Buzz')
      co_filename = /Users/c4obi/projects/python_source/cpython/fizzbuzz.py
      co_firstlineno = 6
      co_flags = 67
      etc...


      but there is no explanation how this can be done programatically, so I wrote my own code:



      # Making the code object for 'my_add' function
      code_obj = compile('my_add', os.path.realpath(__file__), 'exec')

      # Iterating through all instance attributes
      # and calling all having the 'co_' prefix
      for name in dir(code_obj):
      if name.startswith('co_'):
      co_field = getattr(code_obj, name)
      print(f'name:<20 = co_field')


      Output



      co_argcount = 0
      co_cellvars = ()
      co_code = b'ex00x01x00dx00Sx00'
      co_consts = (None,)
      co_filename = /home/minimax/learning_python/oop/source.py
      co_firstlineno = 1
      co_flags = 64
      co_freevars = ()
      co_kwonlyargcount = 0
      co_lnotab = b''
      co_name = <module>
      co_names = ('my_add',)
      co_nlocals = 0
      co_stacksize = 1
      co_varnames = ()


      Question: Have I used the optimal way? How would you solve this problem?










      share|improve this question









      $endgroup$




      I am reading the book: "Obi Ike-Nwosu. Inside The Python Virtual Machine" and have reached the "Code Objects" chapter. This chapter has all code object fields printed out:



      co_argcount = 1
      co_cellvars = ()
      co_code = b'|x00dx01x16x00dx02kx02rx1e|x00dx03x16x00dx02kx02rx1ed\
      x04Sx00n,|x00dx01x16x00dx02kx02r0dx05Sx00nx1a|x00dx03x16x00dx02kx02r
      Bdx06Sx00nx08tx00|x00x83x01Sx00dx00Sx00'
      co_consts = (None, 3, 0, 5, 'FizzBuzz', 'Fizz', 'Buzz')
      co_filename = /Users/c4obi/projects/python_source/cpython/fizzbuzz.py
      co_firstlineno = 6
      co_flags = 67
      etc...


      but there is no explanation how this can be done programatically, so I wrote my own code:



      # Making the code object for 'my_add' function
      code_obj = compile('my_add', os.path.realpath(__file__), 'exec')

      # Iterating through all instance attributes
      # and calling all having the 'co_' prefix
      for name in dir(code_obj):
      if name.startswith('co_'):
      co_field = getattr(code_obj, name)
      print(f'name:<20 = co_field')


      Output



      co_argcount = 0
      co_cellvars = ()
      co_code = b'ex00x01x00dx00Sx00'
      co_consts = (None,)
      co_filename = /home/minimax/learning_python/oop/source.py
      co_firstlineno = 1
      co_flags = 64
      co_freevars = ()
      co_kwonlyargcount = 0
      co_lnotab = b''
      co_name = <module>
      co_names = ('my_add',)
      co_nlocals = 0
      co_stacksize = 1
      co_varnames = ()


      Question: Have I used the optimal way? How would you solve this problem?







      python-3.x






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 13 mins ago









      MiniMaxMiniMax

      1494




      1494




















          0






          active

          oldest

          votes












          Your Answer





          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "196"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216944%2fexploring-code-objects%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f216944%2fexploring-code-objects%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

          格濟夫卡 參考資料 导航菜单51°3′40″N 34°2′21″E / 51.06111°N 34.03917°E / 51.06111; 34.03917ГезівкаПогода в селі 编辑或修订