[Numpy-discussion] Why stripping spaces in strings?
jmiller at stsci.edu
Wed Sep 10 05:51:11 CDT 2003
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.
On Wed, 2003-09-10 at 05:17, Francesc Alted wrote:
> 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)
> >>> print "<%s>" % a._data
> <hello world >
> >>> a._byteView()
> array([[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 32, 32]],
> >>> a._itemsize
> 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.
> Francesc Alted
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
Todd Miller jmiller at stsci.edu
STSCI / ESS / SSB
More information about the Numpy-discussion