Re: problem with string % conversion

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Wed, 22 Jun 1994 12:47:53 -0400

On Jun 22, 12:29, tnb2d@henson.cs.virginia.edu wrote:
>
> Why is this happening? I thought that the "%s" meant print
> the repr of the object, whatever it is.
>
> ---------%< snip %<------------------%< snip %<---------
>
> Python 1.0.2 (Jun 20 1994)
> Copyright 1991-1994 Stichting Mathematisch Centrum, Amsterdam
> >>> a = ([1,2,3], 'howdy!')
> >>> print "%s" % a
> Traceback (innermost last):
> File "<stdin>", line 1
> TypeError: not all arguments converted
>

This will work as expected:

>>> a = [[1,2,3], 'howdy!' ] # list rather than tuple
>>> print "%s" % a

As will:

>>> print "(%s,%s)" % ( [1,2,3], "howdy!" )

And (more illustrative of the problem) so will:

>>> print "%s" % (( [1,2,3], "howdy!" ),) # tuple arg in a singleton-tuple

So, there is a little ambiguity here, and I'm not quite sure as to
whether to classify this as a bug or a (mis)-feature.

( And, I'm too lazy to RTFM at the moment! :-)

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics