George Sakkis wrote: > Michael wrote: > >> Robert, >> >> Thanks to you and everyone else for the help. The "s.split('\x00', >> 1)[0] " solved the problem. > > And a probably faster version: s[:s.index('\x00')]
Yup. About twice as fast for at least one dataset: In [182]: import timeit In [183]: t1 = timeit.Timer("s.split('\\x00', 1)[0]", "s='abc\\x00'*256") In [184]: t2 = timeit.Timer("s[:s.index('\\x00')]", "s='abc\\x00'*256") In [192]: t1.repeat(3, 100000) Out[192]: [0.68063879013061523, 0.67146611213684082, 0.66347002983093262] In [193]: t2.repeat(3, 100000) Out[193]: [0.35819387435913086, 0.35968899726867676, 0.37595295906066895] -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list