[Numpy-discussion] converting "numpy.bytes_" from numpy 1.7.0 to "numpy.string_" of numpy 1.6.1

Sergio Rojas sergio_r@mail....
Sun Apr 7 13:28:33 CDT 2013

Dear all,

I am using a function which under python 2.2.7 and numpy 1.6.1 
returns a "list" (called d) whose elements are of type
"numpy.string_" (see below).

Under python 3.3.0 and numpy 1.7.0 the same function returns the
list as an object of type "builtins.list" whose elements are
of type "numpy.bytes_". 

I am trying to find a way to have the function returns the
same type of object in both versions of python. Acordingly
I am wondering if there is a function which could convert
the "numpy.bytes_" into "numpy.string_". The closes I have
found is using "str(d[1]).lstrip('b')" (see below) but it
wraps the contents of d[1] in double quotes.

In python 2.7.2 In python 3.3.0
numpy 1.6.1 numpy 1.7.0
--------------- ---------------
In [6]: type(d) In [5]: type(d)
Out[6]: list Out[5]: builtins.list

In [7]: d[1] In [6]: d[1]
Out[7]: '05-Jan-00' Out[6]: b'05-Jan-00' 

In [8]: type(d[1]) In [7]: type(d[1]) 
Out[8]: numpy.string_ Out[7]: numpy.bytes_

In [9]: str(d[1]).lstrip('b') In [10]: str(d[1]).lstrip('b')
Out[9]: '05-Jan-00' Out[10]: "'05-Jan-00'"

In [10]: str(d[1]).lstrip('b')[0] In [11]: str(d[1]).lstrip('b')[0]
Out[10]: '0' Out[11]: "'"

I want to have extra double quotes I want to delete the double quotes
enclosing the string stored in d[1] enclosing the string stored in d[1]

Thanks in advance for your help,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130407/9d389c55/attachment.html 

More information about the NumPy-Discussion mailing list