[Tutor] Why has this syntax with multiple arguments ceased to work for the print command?

Bob Gailer bgailer at alum.rpi.edu
Mon Dec 22 23:46:10 EST 2003


At 03:52 PM 12/20/2003, hcohen2 wrote:

>I am certain code like this ran for me without any problem:
>
>print 'You are: %s? and It is the %dth of Dec.' % esp, int(cnt)
>
>both esp are gathered by ... = raw_input('Enter ...') and each works 
>properly as a single argument in test strings.
>
>Now I get:
>
>Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>TypeError: not enough arguments for format string
>
>I tried to study the documentation on the print statement, but the syntax 
>for the argument list left me confused.  [How about some examples in the 
>documentation?]  It appears that the syntax has altered from what was 
>working on version 2.0.x.
>
>I am running this under Mandrake Linux 9.1 using version 2.2.2.
>
>Where am I going wrong?

Try:
print 'You are: %s? and It is the %dth of Dec.' % (esp, int(cnt))

% expects a tuple. Without the parentheses the precedence rules evaluate % 
before , making the statement look like:
print ('You are: %s? and It is the %dth of Dec.' % esp) , int(cnt)

Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell 
-------------- next part --------------

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.551 / Virus Database: 343 - Release Date: 12/11/2003


More information about the Tutor mailing list