This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: softspace confused in nested print
Type: Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: tim.peters Nosy List: gvanrossum, mwh, tim.peters
Priority: normal Keywords:

Created on 2001-11-09 22:33 by tim.peters, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (5)
msg7493 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2001-11-09 22:33
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).
msg7494 - (view) Author: Michael Hudson (mwh) (Python committer) Date: 2002-01-25 10:14
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.
msg7495 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-01-25 14:09
Logged In: YES 
user_id=6380

But there's an easy fix for this one, right?
msg7496 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-01-25 17:48
Logged In: YES 
user_id=31435

It should be easier to fix than to argue about, yes.
msg7497 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2002-03-24 19:26
Logged In: YES 
user_id=31435

Fixed, in

Lib/test/test_softspace.py; new file
Python/ceval.c; new revision: 2.308
History
Date User Action Args
2022-04-10 16:04:37adminsetgithub: 35499
2001-11-09 22:33:49tim.peterscreate