Dumb python questions

Paul Rubin phr-n2001 at nightsong.com
Sun Aug 19 03:27:20 EDT 2001


slinkp23 at yahoo.com (Paul Winkler) writes:
> >  How can I
> >convert it into a packed character string (i.e. represent it in string
> >form with 8 bits/char so I can write it to a file)?  The answers I can
> >think of involve weird kludges and/or are unacceptably slow.
> 
> Hmmm... my first thought was struct.pack but you'd first need to chop
> the long up into (literally) byte-size pieces. And even when you've
> done that, struct.pack() won't take a list as an argument.
> 
> Aside from struct, there's the binascii module which you might find
> useful. For example, here's a pretty fast way to do what you asked
> for:

Yes, thanks, this appears to be about the best way to do it in pure
Python.  The running speed is reasonable for what I'm doing, at least
on my x86 laptop.  Eventually I'd like to run this thing on WinCE
which is part of the reason I don't want to rely on C modules
(I don't have a WinCE C compiler).

Thanks!



More information about the Python-list mailing list