Two newbie questions

Emile van Sebille emile at fenx.com
Thu Nov 9 01:23:27 CET 2000


"Fred Clare" <fred at balzac.scd.ucar.edu> wrote in message
news:8ucosp$7bd$1 at ncar.ucar.edu...
>
>   1.)  Is there a Python equivalent to the C function
"sprintf"?
>        That is, I would like to do a formatted print and
save
>        the result in a Python string.
>

Something like this? (although I'm unfamiliar with
sprintf...)

>>> a = '%s%d' % ('hello ', 1234)
>>> a
'hello 1234'



>   2.)  What is an efficient way of packing a large (i.e. >
1MB)
>        list of integers (that are in the range 0 to 255)
>        into a Python string as a sequence of contiguous
bytes?
>

>>> a = [65,66,67,68]
>>> ''.join(map(chr,a))
'ABCD'


--

Emile van Sebille
emile at fenx.com
-------------------






More information about the Python-list mailing list