string formatting with mapping & '*'... is this a bug?

OKB (not okblacke) BrenBarn at aol.com
Thu Sep 9 14:45:37 EDT 2004


Pierre Fortin wrote:

> Attempting to specify a field width via '*' to a mapping fails....
> 
>>>> "%(two)*d" % (mapping,6)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: format requires a mapping
>>>> "%(two)-*d" % (6,mapping)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: format requires a mapping

    	I don't think this has anything to do with the * thing.  You can't 
mix the sequence and mapping forms of %.  For instance, this also fails

>>> m = {'one': 1, 'two': 2}
>>> "%(two)d %d" % (m, 6)

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in -toplevel-
    "%(two)d %d" % (m, 6)
TypeError: format requires a mapping

    	The error message is telling you the truth: you're passing the % 
operator a tuple, but your format string has a "%(two)" in it, which 
means it requires not a tuple but a mapping.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown



More information about the Python-list mailing list