12 May
2012
12 May
'12
9:25 p.m.
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?