On Fri, 1 Jul 2005 12:09:03 -0500 "Jacob S." <[EMAIL PROTECTED]> wrote:
> > ----- 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. > I haven't lambdas very closely yet, but I understand them to be something of a mini-function (single statement) with no name. Here, I was simply sticking to what I saw in the example. > 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? > Thanks for showing me that - the program still works fine. When you say the statement needs tweaking, is this just a matter of style, or does it affect run-time speed? I'm not timing the program, but didn't happen to notice any difference. Here's screenshots of the old and the new output (if you're interested): http://matheteuo.org/chaddb/screenshots.html The old one is using XFce's terminal, the new is Konsole (easier copy/paste ops). But it's a huge improvement! Don -- evangelinux GNU Evangelist http://matheteuo.org/ http://chaddb.sourceforge.net/ "Free software is like God's love - you can share it with anyone anytime anywhere." _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor