Robert Bradshaw wrote:
> On Sep 30, 2009, at 10:08 AM, Matthew Honnibal wrote:
>
>   
>> Hi,
>> I've only just started using Cython today, and I'm having trouble with
>> the buffer interface indexing described here:
>> http://wiki.cython.org/enhancements/buffer . I want to iterate over a
>> unicode string getting contiguous subsequences.
>>     
>
> I'm not sure what the intended behavior is, given that unicode  
> objects can be stored with various encodings, and, in particular, the  
> default (UTF-8) is a variable-length encoding.
>
>   
>> My Cython function has the following declaration:
>>
>> def parseDoc(object[object] string):
>>     
>
> If you really want a 1D list of objects, I'd just use a list.
>
>   
>> I've tried various Python types, but I always get a runtime error  
>> like:
>>
>> TypeError: 'unicode' does not have the buffer interface
>> TypeError: 'array.array' does not have the buffer interface
>> TypeError: 'buffer' does not have the buffer interface
>>
>> The last one was obtained by calling the built-in buffer() function on
>> the string.
>>
>> I can get a step further by doing cimport numpy and using a numpy
>> array, but then unicode is not one of the supported types, and that
>> doesn't seem like it was the intention --- the docs suggest at Python
>> 2.6+, I shouldn't need the numpy work-around.
>>
>> What am I doing wrong?
>>     
>
> I'm not sure.
>
> I can't even get
>
> def foo(object[double] a):
>      return a[0]
>
> foo(numpy.ndarrray(5))
>
> to work. Dag, any ideas? Is this supposed to work for Py < 3.0?
>   
Try foo(numpy.array([5]).astype(np.double)) ...

I'll answer the rest seperately.

Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to