Skip to main content
GameDev.net gamedev.net
🔒 Locked

Python question about co_varnames

Started by Lucidquiet Apr 3, 2006 at 3:06 PM 1 replies 2k views
Original Post
Lucidquiet
Lucidquiet
The variable in Python co_varnames is a tuple of variables from the function. Does anyone know if the tuple is in ORDER. Example:

LIST='list'

def list_length(result=LIST, lst=LIST, newlst=LIST, body="""
    (cond ((null lst)
            (t)
            (+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-
"Education is when you read the fine print; experience is what you get when you don't." -Pete Seegerwww.lucid-edge.net
smr
smr
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.