[Python-Dev] sys.implementation (original) (raw)

Glenn Linderman v+python at g.nevcal.com
Sat May 12 23:25:53 CEST 2012


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? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20120512/1e32e023/attachment.html>



More information about the Python-Dev mailing list