On Wed, 9 Jan 2008 14:34:26 -0600 "Reedick, Andrew" <[EMAIL PROTECTED]> wrote:
> > -----Original Message----- > > From: [EMAIL PROTECTED] [mailto:python- > > [EMAIL PROTECTED] On Behalf Of John Machin > > Sent: Wednesday, January 09, 2008 3:02 PM > > To: python-list@python.org > > Subject: Re: problem of converting a list to dict > > > > On Jan 10, 6:52 am, "Reedick, Andrew" <[EMAIL PROTECTED]> wrote: > > > > > > A bigger hint: > > > a=i.split('=') > > > print "'%s' splits into " % (i), a > > > > consider: > > (1) using %r instead of '%s' > > Eh, personal preference depending on how sure you are of the > data's type. > > > (2) omitting the redundant space after 'into' > > Some of us coming in from other languages and still aren't used > to the comma adding an unwanted space after everything. I've been > tempted to root around in Python's source code to fix the problem. > > > (3) losing the redundant () around i > > For me, the () is there for readability. Python's sprintf > syntax is odd to begin with, and something like > print "'%s' splits into " % i, a, b, c > means either > 1) you really do want to append b and c after the > sprintf, or > print "'%s' splits into " % (a), b, c > 2) that the formatting string is missing a few things > print "'%s' splits into " % (a, b, c) ## Ooops! > forgot to change it to "%s %5.2d %6.3f" In that case, I'd suggest making the right operand a tuple: print "'%s' splits into" % (i,), a, b, c which some will argue is good style in any case. Or if you just want to aide readers not used to python, use the redundant parens to enforce the default parsing: print ("'%s' splits into" % i), a, b, c <mike -- Mike Meyer <[EMAIL PROTECTED]> http://www.mired.org/consulting.html Independent Network/Unix/Perforce consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list