Stupid string formatting question

Steve Holden sholden at holdenweb.com
Fri May 17 01:03:31 EDT 2002


"Michael S. Fischer" <michael+usenet at dynamine.net> wrote ...
> Why can't I do this?
>
>     def foo(x):
>       # Do some operations on x yielding a and b
>       return a, b
>
>     print "a = %s, b = %s" % (foo(x))
>
> It seems counter-intuitive that although foo is defined to return a 2-item
> tuple, the interpreter just doesn't get it.
>

Clearly you aren't using the same interpreter I am, and you understand
Python better than your interpreter ;-)

>>> def foo():
...     return "spam", "eggs"
...
>>> print "a=%s, b=%s" % foo()
a=spam, b=eggs
>>>

Perhaps if you copy the error message or output you are seeing and paste it
in another posting, with the actual code (unless it's horrendously long) we
could give you better assistance. "The interpreter just doesn't get it"
isn't a terribly helpful trouble report. Did it explode, howl in pain, or
simply display a message?

regards
 Steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list