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

noreply@sourceforge.net noreply@sourceforge.net
Fri, 09 Nov 2001 13:10:46 -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: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
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

"""


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

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