Stupid string formatting question
Joseph Wilhelm
jwilhelm at outsourcefinancial.com
Thu May 16 22:26:32 EDT 2002
On Thu, 2002-05-16 at 19:11, Michael S. Fischer wrote:
> On Thu, May 16, 2002 at 07:03:47PM -0700, Sean 'Shaleh' Perry wrote:
>
> > > OK, here's an example.
> > >
> > > >>> def x():
> > > ... return "a", "b"
> > > ...
> > > >>> print "%s/%s/%s/%s" % ("hi", "there", x())
> > > Traceback (most recent call last):
> > > File "<stdin>", line 1, in ?
> > > TypeError: not enough arguments for format string
> > >
> >
> > you just returned ("hi, "there", ("a", "b")) which is len(3) not 4.
>
> OK. What can I do to make this work?
>
> --
> Michael S. Fischer / michael at dynamine.net / +1 650-533-4684
> Lead Hacketeer, Dynamine Consulting, Silicon Valley, CA
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
Well this is a little (Okay, maybe more than a little) ugly... but you
could do something like this:
>>> def x():
... return "a","b"
...
>>> args = [ "hi", "there" ]
>>> args.extend( x() )
>>> print "%s/%s/%s/%s" % tuple( args )
hi/there/a/b
>>>
--Joseph Wilhelm
More information about the Python-list
mailing list