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: String termination on Linux
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, ezio.melotti, georg.brandl, jjanis, r.david.murray, terry.reedy
Priority: normal Keywords:

Created on 2012-06-06 14:47 by jjanis, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg162413 - (view) Author: Jānis (jjanis) Date: 2012-06-06 14:47
test = "Hi there :)"
    print len(test), test // Prints "11 Hi there :)"
    test = test.replace(" ", "\x00")
    print len(test), test // Prints "11 

On Windows '\x00' is same as ' ', but on linux string is terminated at first occurance of '\x00'. Results on problems with pySerial and binary data, so I can't replace '\x00' with ' '.
msg162414 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-06-06 15:11
Windows makes \x00 a space?  How odd.

This is the result for me on linux:

Python 2.7.3+ (2.7:1f5d2642929a, May 25 2012, 12:47:34) 
[GCC 4.5.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> test = "Hi there :)"
>>> print len(test), test
11 Hi there :)
>>> test = test.replace(" ", "\x00")
>>> print len(test), test
11 Hithere:)

Your comment on the last line of your example seems to have been truncated, so I'm not sure what you really saw.
msg162538 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-06-08 17:18
Jānis, please present examples as proper python -- indentation and comment char -- so others can copy/paste to run without editing.
In Idle (tkinter -- tk), '\0' is displayed as a wider space than ' '. The console is fixed pitch, so it cannot do that.

I suspect that the response of a window to \0 is window system dependent and probably out of our control. If so, this issue should be closed.
msg162902 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2012-06-15 14:17
Jānis:
> Prints "11 

This is not what I get on Linux: I see "11 Hithere:)" because the console chooses to not print the \x00.  The character is present in the output stream though.

Did you really got a truncated output? How did you run the above script?
msg185416 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2013-03-28 10:08
Closing due to lack of response.
History
Date User Action Args
2022-04-11 14:57:31adminsetgithub: 59224
2013-03-28 10:08:29georg.brandlsetstatus: pending -> closed

nosy: + georg.brandl
messages: + msg185416

resolution: works for me
2013-01-15 16:57:06serhiy.storchakasetstatus: open -> pending
2012-06-15 14:17:21amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg162902
2012-06-15 08:08:48ezio.melottisetnosy: + ezio.melotti
2012-06-08 17:18:00terry.reedysetnosy: + terry.reedy

messages: + msg162538
title: Sting termination on Linux -> String termination on Linux
2012-06-06 15:11:44r.david.murraysetnosy: + r.david.murray
messages: + msg162414
2012-06-06 14:47:44jjaniscreate