Stupid string formatting question
Bengt Richter
bokr at oz.net
Thu May 16 21:53:02 EDT 2002
On Fri, 17 May 2002 01:19:59 -0000, "Michael S. Fischer" <michael+usenet at dynamine.net> wrote:
>Why can't I do this?
No apparent reason.
>
> 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.
>
Try posting an example copied and pasted from an interactive session.
It looks like you did something else.
>>> def foo(x):
... # Do some operations on x yielding a and b
... a = 'eigh-'+x
... b = 'bee-'+x
... return a,b
...
>>> x='exx'
>>> print "a = %s, b = %s" % (foo(x))
a = eigh-exx, b = bee-exx
also, since a tuple is returned
>>> print "a = %s, b = %s" % foo(x)
a = eigh-exx, b = bee-exx
Regards,
Bengt Richter
More information about the Python-list
mailing list