sprintf behaviour

Dan Bishop danb_83 at yahoo.com
Sat Feb 22 18:01:11 EST 2003


"Andrew Wilkinson" <ajw126NO at SPAMyork.ac.uk> wrote in message news:<3e579df4$0$9701$65c69314 at mercury.nildram.net>...
> >>> print "-- %2$s -- %1$s --" % ('a', 'b')
> 
> Python isn't C you know! You can't simply copy things from C to Python and
> expect them to work.
> 
> Take a look at...
> http://www.python.org/doc/current/lib/typesseq-strings.html
> 
> And you'll see that what you actually want is just...
> >>> print "-- %s -- %s --" % ('a', 'b')

I think you mean

print "-- %s -- %s --" % ('b', 'a')

or

a = 'a'
b = 'b'
print "-- %(b)s -- %(a)s --" % vars()




More information about the Python-list mailing list