[NumPy-Tickets] [NumPy] #2024: NULL bytes removed from end of string in NumPy array

NumPy Trac numpy-tickets@scipy....
Wed Jan 18 19:46:14 CST 2012

#2024: NULL bytes removed from end of string in NumPy array
 Reporter:  edcjones                |       Owner:  somebody   
     Type:  defect                  |      Status:  new        
 Priority:  normal                  |   Milestone:  Unscheduled
Component:  numpy.core              |     Version:  1.4.1      
 Keywords:  NULL terminated string  |  
 I use Debian stable on a PC. The distribution uses Python 2.6.6 and
 NumPy 1.4.1.

 In Python and I assume in NumPy, strings are not NULL-terminated.
 The following program strips the zero bytess from the end of a string:

 #! /usr/bin/env python

 import numpy

 DT = numpy.dtype([('hashcode',  numpy.str_, 16)])
 badstring = 4 * chr(0) + 'ABCDEFGH' + 4 * chr(0)
 print repr(badstring)
 arr = numpy.array((badstring,), dtype=DT)
 print repr(arr)
 s = str(arr['hashcode'])
 print len(s), repr(s)

 The output is:

       dtype=[('hashcode', '|S16')])
 12 '\x00\x00\x00\x00ABCDEFGH'

 It appears that the string is being treated like a C-string somewhere in

Ticket URL: <http://projects.scipy.org/numpy/ticket/2024>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list