Null-terminated strings with struct module?
Paul Rubin
http
Fri Mar 5 19:42:39 EST 2004
Roy Smith <roy at panix.com> writes:
> s1 = self.directory + "\0"
> s2 = self.fileName + "\0"
> s3 = self.dateString + "\0"
> s4 = self.name + "\0"
> s5 = struct.pack ("!IB", self.id, self.perTargetFlag)
> data = s1 + s2 + s3 + s4 + s5
>
> which is pretty ugly. Is there a neater way to do this?
Shrug.
data = "%s\0%s\0%s\0%s\0%s"% (self.directory, self.fileName,
self.dateString, self.name,
struct.pack (...))
Dunno if that's better or worse.
More information about the Python-list
mailing list