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

Georg Brandl g.brandl at gmx.net
Wed Oct 21 12:34:23 CEST 2009


Eero Nevalainen schrieb:
>  From the (creative) laziness department:
> 
> Whenever my module A needs to pass a lot of data to module B, I find 
> myself making a factory function in module B for creating the datastructures
> 
> def my_factory_function(a, b, c):
>      # input checking
>      res.a = a
>      res.b = b
>      res.c = c
>      return res
> 
> I believe this is fairly common.
> 
> Since the fields are already defined in the function signature, I'd 
> prefer to not repeat myself and write something like this:
> 
> def my_factory_function(a, b, c):
>      args = locals()
>      # input checking
>      return namedtuple('MyTypeName', args)
> 
> 
> This would perceivably be possible, if locals() returned an OrderedDict 
> and an appropriate namedtuple factory function was added.

Sorry, I don't understand *at all* what you are proposing here.

Georg

-- 
Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.




More information about the Python-ideas mailing list