Stupid string formatting question

Gonçalo Rodrigues op73418 at mail.telepac.pt
Thu May 16 21:40:27 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?
>
>    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.

There must be something you are not telling us. It works fine for me,
e.g.:

PythonWin 2.2.1 (#34, Apr 15 2002, 09:51:39) [MSC 32 bit (Intel)] on
win32.
Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) -
see 'Help/About PythonWin' for further copyright information.
>>> def test():
... 	return 'test1', 'test2'
... 
>>> print "a = %s, b=%s" % test()
a = test1, b=test2
>>> print "a = %s, b=%s" % (test())
a = test1, b=test2
>>> 

Give us the exact error messages you are getting, maybe we can figure
something out.

Best and good luck,
Gonçalo Rodrigues



More information about the Python-list mailing list