<br><br><div class="gmail_quote">2009/10/21 Eero Nevalainen <span dir="ltr"><<a href="mailto:eero.nevalainen@indagon.com">eero.nevalainen@indagon.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
>From the (creative) laziness department:<br>
<br>
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<br>
<br>
def my_factory_function(a, b, c):<br>
    # input checking<br>
    res.a = a<br>
    res.b = b<br>
    res.c = c<br>
    return res<br>
<br>
I believe this is fairly common.<br>
<br></blockquote><div><br>The C# syntax for this  (anonymous types new in C# 3.0) is:<br><br>    var obj = <span style="color: blue;">new</span> { prod.Color, prod.Price }<span id="ctl00_MTCS_main_ctl08"></span><br><br>C# creates what is effectively a named tuple parsing the field names from the way you construct it. The closest Python syntax would be something like:<br>
<br>    obj = {Color=foo, Price=bar}<br><br>Or as we seem to be overloading curly braces a great deal now, how about:<br><br>    obj = (Color=foo, Price=bar)<br><br>All the best,<br><br>Michael<br> </div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

Since the fields are already defined in the function signature, I'd prefer to not repeat myself and write something like this:<br>
<br>
def my_factory_function(a, b, c):<br>
    args = locals()<br>
    # input checking<br>
    return namedtuple('MyTypeName', args)<br>
<br>
<br>
This would perceivably be possible, if locals() returned an OrderedDict and an appropriate namedtuple factory function was added.<br>
<br>
related discussion is in:<br>
<a href="http://kbyanc.blogspot.com/2007/07/python-aggregating-function-arguments.html" target="_blank">http://kbyanc.blogspot.com/2007/07/python-aggregating-function-arguments.html</a><br>
<a href="http://code.activestate.com/recipes/500261/" target="_blank">http://code.activestate.com/recipes/500261/</a><br>
<br>
Does this seem familiar or useful to anyone besides me?<br><font color="#888888">
<br>
-- <br>
Eero Nevalainen<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br><a href="http://www.ironpythoninaction.com/">http://www.ironpythoninaction.com/</a><br><br><br>