Re: print - bug or feature - concatenated format strings in a print statement

2009-03-18 Thread Steven D'Aprano
On Tue, 17 Mar 2009 22:41:26 -0700, John Machin wrote: > On Mar 18, 4:19 pm, Matt Nordhoff wrote: >> The implicit string concatenation is actually done by the compiler; it >> isn't an operator at all. Look: >> >> >>> import dis >> >>> def f(): >> >> ...     return "foo" "bar" >> ...>>> dis.dis(f

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-17 Thread John Machin
On Mar 18, 4:19 pm, Matt Nordhoff wrote: > bdb112 wrote: > > Thanks for all the replies: > > I think I see now - % is a binary operator whose precedence rules are > > shared with the modulo operator regardless of the nature of its > > arguments, for language consistency. > > I understand the argum

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-17 Thread Matt Nordhoff
bdb112 wrote: > Thanks for all the replies: > I think I see now - % is a binary operator whose precedence rules are > shared with the modulo operator regardless of the nature of its > arguments, for language consistency. > I understand the arguments behind the format method, but hope that the > sli

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-17 Thread bdb112
Thanks for all the replies: I think I see now - % is a binary operator whose precedence rules are shared with the modulo operator regardless of the nature of its arguments, for language consistency. I understand the arguments behind the format method, but hope that the slightly idiosyncratic print(

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread Scott David Daniels
bdb112 wrote: ... the difference between ... print(" %d, %d, buckle my shoe" % (1,2)) ... and ... print(" %d, " + " %d, buckle my shoe" % (1,2)) # a bug or a feature? A feature. a + b % c is a + (b % c) But do note that string constant concatentation is higher priority than the other ope

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread R. David Murray
> On Mar 16, 5:00 pm, bdb112 wrote: > > #   is the difference between > > print(" %d,  %d, buckle my shoe" % (1,2)) > > #   and > > print(" %d, " + " %d, buckle my shoe" % (1,2)) > > # a bug or a feature? It is correct behavior. On the other hand, it is one of the, well, bugs, that is avoided by

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread alex goretoy
> > print(10 + 20 % 7) > a bug or a feature? It is a feature print ((10+20) % 7) -Alex Goretoy http://www.goretoy.com -- http://mail.python.org/mailman/listinfo/python-list

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread John Machin
On Mar 16, 7:00 pm, bdb112 wrote: > #   is the difference between > print(" %d,  %d, buckle my shoe" % (1,2)) > #   and > print(" %d, " + " %d, buckle my shoe" % (1,2)) > # a bug or a feature? Here's a question for you: Is the difference between print(30 % 7) and print(10 + 20 % 7) a bug or

Re: print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread bdb112
#whoops, the first output is actually 1, 2, buckle my shoe # in case it wasn't obvious On Mar 16, 5:00 pm, bdb112 wrote: > #   is the difference between > print(" %d,  %d, buckle my shoe" % (1,2)) > #   and > print(" %d, " + " %d, buckle my shoe" % (1,2)) > # a bug or a feature? > > First ou

print - bug or feature - concatenated format strings in a print statement

2009-03-16 Thread bdb112
# is the difference between print(" %d, %d, buckle my shoe" % (1,2)) # and print(" %d, " + " %d, buckle my shoe" % (1,2)) # a bug or a feature? First output ... print(" %d " + " %d, buckle my shoe" % (1,2)) Second output TypeError: not all arguments converted during string formatting Versio