On 5/12/2012 10:50 AM, Eric Snow wrote:
given a normal (dict-based)
object you can use vars() to turn it into a dict:

>>>  data = SomeClass(a=1, b=2, c=3)
>>>  ns = vars(data)
>>>  ns['a']
1
>>>  ns['b']
2
>>>  ns['c']
3

I'll grant that it doesn't work for some objects (like named tuples),

Why not?  Seems like it could, with a tweak to vars ...

named tuples already have a method to return a dict.
vars already has a special case to act like locals.

So why not add a special case to allow vars to work on named tuples?
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to