[Python-bugs-list] [ python-Bugs-480215 ] softspace confused in nested print

noreply@sourceforge.net noreply@sourceforge.net
Sun, 24 Mar 2002 11:26:54 -0800


Bugs item #480215, was opened at 2001-11-09 17:33
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=480215&group_id=5470

Category: Python Interpreter Core
Group: None
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Tim Peters (tim_one)
>Assigned to: Tim Peters (tim_one)
Summary: softspace confused in nested print

Initial Comment:
Adapted from a c.l.py report:

class C:
.   def __str__(self):
.       print "a"
.       return "b"
print C()

The output is " a\nb\n" -- note the surprising leading 
space.  This is because PRINT_ITEM forces softspace to 
1 *before* converting the output item (so softspace is 
1 when we get into __str__, despite that nothing yet 
has been written).

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-03-24 14:26

Message:
Logged In: YES 
user_id=31435

Fixed, in

Lib/test/test_softspace.py; new file
Python/ceval.c; new revision: 2.308

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2002-01-25 12:48

Message:
Logged In: YES 
user_id=31435

It should be easier to fix than to argue about, yes.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-01-25 09:09

Message:
Logged In: YES 
user_id=6380

But there's an easy fix for this one, right?

----------------------------------------------------------------------

Comment By: Michael Hudson (mwh)
Date: 2002-01-25 05:14

Message:
Logged In: YES 
user_id=6656

In my bid to reduce the number of unassigned bugs I say: so
what?

print is magical, maybe too magical, but I thought the
consensus was that it's not worth changing.  Having
side-effects in __str__ methods is gross anyway.

----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=480215&group_id=5470