----- Original Message ----- 
From: "Don Parris" <[EMAIL PROTECTED]>
To: <tutor@python.org>
Sent: Thursday, June 30, 2005 12:23 AM
Subject: Re: [Tutor] Alternative File I/O for Tuples (fwd)


> On Wed, 29 Jun 2005 14:09:41 -0400
> Kent Johnson <[EMAIL PROTECTED]> wrote:
>
>> Don Parris wrote:
>> > ### playing with wrapfunc (all other args are the same) ###
>> > wrapfunc=lambda x:wrap_onspace(str(rows), x))
>> >
>> > also
>> > wrapfunc=lambda x:str(wrap_onspace(rows, x)))
>>
>> This is way off base. wrap_onspace takes two arguments - the string to
>> wrap, and the width to wrap to. You are passing it two arguments - the
>> tuple of tuples to print, and the string to wrap.
>>
>> >
>
> Success!!!
>
>    mbrPhone = open('mbrPhone.txt', 'w')
>    mbrPhone.write(indent(Results, hasHeader=False, separateRows=False,
>    prefix='', postfix='', justify='left', wrapfunc=lambda x:str(x)))
>    mbrPhone.close()

Just a point.

You don't need the extra lambda at wrapfunc.

Writing it as...

mbrPhone.write(indent(Results, hasHeader=False, separateRows=False,
prefix='', postfix='',justify='left',wrapfunc=str))

will work fine.

A lambda definition is simple, and you already grasp most of the concept, 
but the above shows a little needed tweaking.

def a(b,c=d):
    return somefunc(e)

is equivalent to

a = lambda b,c=d: somefunc(e)

However,

def wrapfunc(x):
    return str(x)

can be shortened to

wrapfunc = lambda x:str(x)

which can be shortened even further to

wrapfunc = str

I guess the moral of the story is--why bother making wrapfunc a function 
when you can set it equal to a function -- str --  and it's still the same?

Okay, I'm done.

Jacob


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to