[Numpy-discussion] Why stripping spaces in strings?
Todd Miller
jmiller at stsci.edu
Wed Sep 10 05:51:11 EDT 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.
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 at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
--
Todd Miller jmiller at stsci.edu
STSCI / ESS / SSB
More information about the NumPy-Discussion
mailing list