
Hi,
A user of pytables recently asked me why it truncates the trailing spaces on strings. I have to explain him that the information is there, but the strings module of the numarray package deliberately strips off the trailing spaces when printing:
from numarray import strings a=strings.array("hello world ") print a
['hello world']
print "<%s>" % a
<['hello world']>
len(a[0])
11
however:
print "<%s>" % a._data
<hello world >
a._byteView()
array([[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 32]], type=UInt8)
a._itemsize
13
In the beginning I thought that this was a nice feature, but when people is using numarray.strings objects as containers (for example for Pickled objects), that can be rather confusing, and I would prefer to see all the trailing blanks.
But as I am not completely sure, I just would like to discuss the pro's and con's of the current printing apprach.
Cheers,

Take a look at RawCharArray instead of CharArray. CharArray is a RawCharArray with specific stripping and padding behaviors and some extra methods. RawCharArray should be the starting point for this kind of discussion; it may do what you want as-is, or you can tell me where it's falling short of what you need.
Todd
On Wed, 2003-09-10 at 05:17, Francesc Alted wrote:
Hi,
A user of pytables recently asked me why it truncates the trailing spaces on strings. I have to explain him that the information is there, but the strings module of the numarray package deliberately strips off the trailing spaces when printing:
from numarray import strings a=strings.array("hello world ") print a
['hello world']
print "<%s>" % a
<['hello world']>
len(a[0])
11
however:
print "<%s>" % a._data
<hello world > >>> a._byteView() array([[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 32]], type=UInt8) >>> a._itemsize 13
In the beginning I thought that this was a nice feature, but when people is using numarray.strings objects as containers (for example for Pickled objects), that can be rather confusing, and I would prefer to see all the trailing blanks.
But as I am not completely sure, I just would like to discuss the pro's and con's of the current printing apprach.
Cheers,
-- Francesc Alted
This sf.net email is sponsored by:ThinkGeek Welcome to geek heaven. http://thinkgeek.com/sf _______________________________________________ Numpy-discussion mailing list Numpy-discussion@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/numpy-discussion

Yups, RawCharrArray do the trick:
strings.array([["hello world ","pp\0"]], kind=strings.CharArray)
CharArray([['hello world', 'pp']])
strings.array([["hello world ","pp\0"]], kind=strings.RawCharArray)
RawCharArray([['hello world ', 'pp\x00 ']])
Thanks for the hint,
A Dimecres 10 Setembre 2003 14:40, Todd Miller va escriure:
Take a look at RawCharArray instead of CharArray. CharArray is a RawCharArray with specific stripping and padding behaviors and some extra methods. RawCharArray should be the starting point for this kind of discussion; it may do what you want as-is, or you can tell me where it's falling short of what you need.
Todd
participants (2)
-
Francesc Alted
-
Todd Miller