[Pyrex] Handling bytes
    Brad Schick 
    schickb at gmail.com
       
    Thu May  8 18:26:12 CEST 2008
    
    
  
On 5/8/2008 12:05 AM, Stefan Behnel wrote:
> BTW, work has started in Cython to generate code for Py3. It's still a long
> way, but at least we're getting closer. :)
>
>   
That's great, thanks.
>> It just seems
>> so ugly in what is otherwise a fairly clean language. Particularly when
>> the data sometimes starts life as a list. How do you go about stuffing
>> 'bytes' into a string? With arrays as below? Or with cStringIO? Yuck and
>> yuck ;)
>>     
> Sure, why not? You can also create an empty string and fill it yourself:
>
>    cdef int i
>    cdef char* s
>    py_s = PyString_FromStringAndSize(NULL, len(data))
>    s = py_s
>    for i in range(len(data)):
>        s[i] = l[i]
>   
I meant in python code. In other words, the code calling into the pyrex 
module that will need to cram everything into strings. That's fine if it 
the data starts in a string or file, but its pretty ugly and inefficient 
if it starts in some other sequence like a list.
-Brad
    
    
More information about the Pyrex
mailing list