struct.unpack null-terminated string

Alex Martelli aleaxit at
Fri Aug 3 14:24:55 CEST 2001

"Xavier Defrang" <xavier at> wrote in message
news:mailman.996832925.27921.python-list at
> Hello,
> How do I unpack a null-terminated string with the struct module?  I
> couldn't find it in the lib reference... maybe do i have to upgrade my
> glasses?

I don't think it's supported -- a C struct can't specify that one of
its fields is variable length (e.g. sentinel-terminated).  You can
find the \0 and break the string you're unpacking there, etc...


More information about the Python-list mailing list