Writing an end of string character in Python

Grant Edwards grante at visi.com
Thu May 31 13:10:46 EDT 2001


In article <mailman.991323107.25262.python-list at python.org>, Skip Montanaro wrote:
>
>    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)

Or:

  s = whereverYourStringsComeFrom()
  
  open("/tmp/trash","w").write(s+'\000')

-- 
Grant Edwards                   grante             Yow!  My TOYOTA is built
                                  at               like a... BAGEL with CREAM
                               visi.com            CHEESE!!



More information about the Python-list mailing list