[Python-bugs-list] [ python-Bugs-480188 ] printing unicode objects

noreply@sourceforge.net noreply@sourceforge.net
Tue, 20 Nov 2001 07:07:49 -0800


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

Category: Python Interpreter Core
Group: Python 2.1.1
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: M.-A. Lemburg (lemburg)
Summary: printing unicode objects

Initial Comment:
"""

In a print statement using a trailing comma (to
suppress printing a newline) printing a unicode object
that contains a trailing newline sometimes prints an
extra space.

If I have a unicode object, u, that contains a trailing
newline, then...

   print str(u),     # behaves as expected

   print u.encode(), # behaves as expected

   print u,          # the newline isn't recognized
                     # and the next print
                     # inserts a space

It appears that the implicit form of encoding the
unicode object doesn't quite work right with print.

The following code illustrates my problem.  My output
follows.

"""

import sys
print sys.version

s = 'This is a test\n'
u = unicode(s)

print
print s,
print s,
print s,
print
print str(u),
print str(u),
print str(u),
print
print u.encode(),
print u.encode(),
print u.encode(),
print
print u,
print u,
print u,


"""
My output:

2.1.1 (#1, Aug 28 2001, 19:51:39) 
[GCC 2.96 20000731 (Red Hat Linux 7.1 2.96-85)]

This is a test
This is a test
This is a test

This is a test
This is a test
This is a test

This is a test
This is a test
This is a test

This is a test
 This is a test
 This is a test

"""


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

>Comment By: M.-A. Lemburg (lemburg)
Date: 2001-11-20 07:07

Message:
Logged In: YES 
user_id=38388

I'll checkin a fix for this today.


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

Comment By: Daniel Popowich (dpopowich)
Date: 2001-11-09 14:57

Message:
Logged In: YES 
user_id=372379

When I submitted this but I didn't realize the form
was going to eat my formatting.  The last few lines
of the output has leading spaces.  Run the sample
code to see what I mean.


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

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