On Sat, Jun 8, 2013 at 8:35 PM, Alan Cabrera <[email protected]> wrote: > On Jun 8, 2013, at 2:19 PM, Greg Stein <[email protected]> wrote: >> On Jun 8, 2013 12:56 PM, "Daniel Shahaf" <[email protected]> wrote: >>> On Sat, Jun 08, 2013 at 12:08:57AM -0000, [email protected] wrote: >>>> + print '%s: voter must be an Internet e-mail address.' % (SCRIPT,) > > I guess I'm not not the commits list yet.
[email protected] > Is it really good form to use a single member tuple for this kind of print > statement? I ask this as a Java weenie who is learning the ropes. It seems > like a lot of syntactic noise. Well... it is kind of six-of-one / half-dozen-another. The % operator takes a string and a sequence. If the right-hand is *not* a sequence, then it requires the left-hand format string to have a single substitution. So yes, I could have just said "..." % SCRIPT. But you can sometimes get into edge-case typos. Consider: "%s: problem with %s" % SCRIPT That actually works great if SCRIPT is a two-character string. Strings are sequences. It will tear apart the string and substitute each character. If the string is not 2-chars long, then you get a mismatch between format codes and the right-hand value. By saying (SCRIPT,), I am making it absolutely clear that I am providing ONE value to the interpolation. So yeah: some syntactic noise that isn't strictly needed. I think it is mostly based on mood. Tho in this case, working on a shared codebase (rather than a personal python script), I think the clarity of a one-tuple can be helpful. *shrug* >>> Any reason not to use Python 3? Or at least the common subset of py2 and >> py3? >> >> Python 2.7 is preinstalled on my Mac. It is generally more available, and I >> believe better-supported by 3rd-class extensions/libraries. > > print 'Because parentheses have no place in print statements' > print "other than for %s %s formatting options' % ('super', 'awesome') > > +1 for 2.6/2.7 > > We can use Python 3 if there's ever a feature we need. Heh. Yeah... Cheers, -g
