Jump to content
  • Advertisement
Sign in to follow this  

Python question about co_varnames

This topic is 4487 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The variable in Python co_varnames is a tuple of variables from the function. Does anyone know if the tuple is in ORDER. Example:

def list_length(result=LIST, lst=LIST, newlst=LIST, body="""
    (cond ((null lst)
            (+1 my)""" ):
    """'My version of the length function for lists'"""
    random_var="not really useful"
    return locals()

>>> import MyMod
>>> MyMod.list_length.func_code.co_varnames
('result', 'lst', 'newlst', 'body', 'random_var')

// However the hash return is, or course, not in order:
>>>  vars = MyMod.list_length()
>>>  vars
{'body': '\n    (cond ((null lst)\n            (t)\n            (+1 my)', 'rando
m_var': 'not really useful', 'lst': 'list', 'newlst': 'list', 'result': 'list'}

I've looked and found nothing stating it is or not in ORDER (I'm thinking and hoping that it is in ORDER). That way I can use the order of co_varnames for pulling the right keys out of the vars hash. L-

Share this post

Link to post
Share on other sites
What are you trying to accomplish? I've looked at your example for about five minutes and I can't figure out what you're goal is. vars is also a dict in your example.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!