Writing an end of string character in Python

Skip Montanaro skip at pobox.com
Thu May 31 11:30:04 EDT 2001


    Charlie> I read in PP2E that "\0" does not terminate the string in
    Charlie> Python. Is there anyway I can force it to?

You can safely embed ASCII NUL characters in Python strings, so if you need
to write a string containing one, no problem:

    s = "I'm a NUL-terminated string\000"
    open("/tmp/trash", "w").write(s)

-- 
Skip Montanaro (skip at pobox.com)
(847)971-7098




More information about the Python-list mailing list