[Python-ideas] Syntax for making stuct / record / namedtuples

Mark Tolonen metolone+gmane at gmail.com
Wed Oct 21 16:53:54 CEST 2009


"Carl Johnson" 
<cmjohnson.mailinglist at gmail.com> wrote in 
message news:3bdda690910210316s1bd9630exa83b9fd147644cc3 at mail.gmail.com...
> I would also appreciate a faster way to do the boilerplate in an
> __init__ of saying self.arg1 = arg1, self.arg2 = arg2, etc. But what
> would be the global implications of changing locals() to an odict? Is
> that backwards compatible? If not, perhaps we could add a new builtin,
> say "olocals()" instead?

>>> class X:
...  def __init__(self,a,b,c):
...   self.__dict__.update(locals())
...
>>> x=X(1,2,3)
>>> x.a
1
>>> x.b
2
>>> x.c
3

-Mark





More information about the Python-ideas mailing list