constructing bytestrings

Lenny G. alengarbage at yahoo.com
Fri Aug 12 06:17:31 CEST 2005


I use 's = os.read(fd, 12)' to grab 12 bytes from a file.  Now, I want
to create a string, s1, which contains 16-12=4 bytes: 4,0,0,0, followed
by the contents of s.

I know how to 's1 = "\x04\x00\x00\x00"' and how to 's3 = s1+s', but I
don't know how to construct s1 dynamically (i.e., given N, construct
"N" followed by N-1 "0", where "N" and "0" are single byte values with
N<16).  How do I do this?




More information about the Python-list mailing list