----- Message from [EMAIL PROTECTED] ---------
    Date: Wed, 02 Jul 2008 14:32:27 -0400
    From: bob gailer <[EMAIL PROTECTED]>

[EMAIL PROTECTED] wrote:
[snip]


In a case like

print '%s%s' %42 , 333
...
TypeError: not enough arguments for format string

it would be ambiguous whether 333 was intended as a second formatting argument or as a second thing to be printed.

Here's where the Language Reference comes in handy:

print_stmt ::= "print" ( [expression ("," expression)* [","]]
expression_list ::= expression ( "," expression )* [","] # An
expression list containing at least one comma yields a tuple

Given that, there is no ambiguity in print '%s%s' %42 , 333



I think I poorly expressed my intent. It was my starting point that
42, 333
provides a tuple, even absent the parens.

What I meant to express was the hypothesis that
print '%s%s' %42 , 333
even while following the '%' with a tuple might be ruled out due to a possible 'ambiguity in the intent', not in the syntax. I meant to suggest that the perhaps the parens were required to make it explicit where the end of the '%'-following tuple was, and where the 'more stuff to print, distinct from the format-string stuff' began.

Were the following legal:
c = "I am distinct from the format string, but that is hard to see."
print "%s%s" % 42, 333, c
...
TypeError: not enough arguments for format string

it would be harder to parse than:
c = "I am obviously distinct from the format string."
print "%s%s" % (42, 333), c
42333 I am obviously distinct from the format string.


If not that, then why are the parens required?

Best,

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

Reply via email to