[Numpy-discussion] str/bytes object from arr.data?

2010-09-27 Thread Francesc Alted
Hi,

Anybody knows a way to get a str object (bytes for Python = 2.6) out of 
a buffer object (i.e. the .data attribute of ndarrays) without copying 
data?

I need this for avoid creating a new function that deals with buffer 
objects (instead of reusing the one for str/byte objects that I already 
have).  So, a matter of laziness :-)

Thanks,

-- 
Francesc Alted
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] str/bytes object from arr.data?

2010-09-27 Thread Zachary Pincus
As str objects are supposed to be immutable, I think anything  
official that makes a string from a numpy array is supposed to copy  
the data. But I think you can use ctypes to wrap a pointer and a  
length as a python string.

Zach


On Sep 27, 2010, at 8:28 AM, Francesc Alted wrote:

 Hi,

 Anybody knows a way to get a str object (bytes for Python = 2.6)  
 out of
 a buffer object (i.e. the .data attribute of ndarrays) without copying
 data?

 I need this for avoid creating a new function that deals with buffer
 objects (instead of reusing the one for str/byte objects that I  
 already
 have).  So, a matter of laziness :-)

 Thanks,

 -- 
 Francesc Alted
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] str/bytes object from arr.data?

2010-09-27 Thread Francesc Alted
A Monday 27 September 2010 15:04:14 Zachary Pincus escrigué:
 As str objects are supposed to be immutable, I think anything
 official that makes a string from a numpy array is supposed to copy
 the data. But I think you can use ctypes to wrap a pointer and a
 length as a python string.

Yeah, ctypes is very powerful indeed.  Thanks!

-- 
Francesc Alted
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion