Error on string formatting

Ivan Van Laningham ivanlan at callware.com
Tue Feb 8 18:18:31 EST 2000


Judy Hawkins wrote:
> 
> Why this:
> 
> >>> buf = '%0.*f' % 3, 4.1
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> TypeError: not enough arguments for format string
> 
> The comparable statement in C works fine, and the Essential Reference
> says I can do this kind of asterisk thing.
> 
> Judy Hawkins
> 
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> --
> http://www.python.org/mailman/listinfo/python-list

buf = '%0.*f' % 3, 4.1  ==> buf = '%0.*f' % (3, 4.1)

The % formatting operator requires a tuple, unless only there is only
one argument called for, in which case the single argument is
automatically converted to a tuple.

<lists-won't-work-either,-but-dictionaries-will>-ly y'rs,
Ivan
----------------------------------------------
Ivan Van Laningham
Callware Technologies, Inc.
ivanlan at callware.com
http://www.pauahtun.org 
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps:  Cu Chi, Class of '70
Author:  Teach Yourself Python in 24 Hours




More information about the Python-list mailing list