pre-PEP: Suite-Based Keywords

Ron_Adam radam2_ at _tampabay.rr.com
Mon Apr 18 17:59:25 EDT 2005


On Mon, 18 Apr 2005 14:06:08 -0700, "Robert Brewer"
<fumanchu at amor.org> wrote:

>Reinhold Birkenfeld wrote:
>> >y = (f(11, 22, x=1, y='y for f') *
>> >     g(*args_from_somewhere,
>> >       x='x for g', y='y for g',
>> >       foo=lambda: return 'foo for g'))
>> >
>> >would be my current way to express this. But still, the less lines,
>> >the less confusing it is.
>
>And Ron Adam replied:
>> I would probably do it this way.
>> 
>> y = f(11, 22, x=1, y='y for f') 		\
>>          * g( *args_from_somewhere,
>>               x='x for g', 
>>               y='y for g',
>>               foo=lambda: return 'foo for g' )
>
>Which are both prettier, until you actually try to use them:
>
>>>> g( *args_from_somewhere, x='x for g', y='y for g', foo=lambda:
>return 'foo for g' )
>Traceback (  File "<interactive input>", line 1
>    g( *args_from_somewhere, x='x for g', y='y for g', foo=lambda:
>return 'foo for g' )
>                             ^
>SyntaxError: invalid syntax
>

I didn't test that particular part..  but this should work.  It wasn't
the fault of the formatting. ;-)

def f(a,b,x=None,y=None):
    return 1
    
def g( args,x=None,y=None,foo=None):
    return 1

args_from_somewhere = (23,24)

y = f(11, 22, x=1, y='y for f') 		\
         * g( args_from_somewhere,
              x='x for g', 
              y='y for g',
              foo=lambda foo: 'foo for g' )

print y

1


>
>Robert Brewer
>MIS
>Amor Ministries
>fumanchu at amor.org




More information about the Python-list mailing list