[Numpy-discussion] np.loadtxt : yet a new implementation...

Christopher Barker Chris.Barker@noaa....
Wed Dec 3 13:12:49 CST 2008


Pierre GM wrote:
> On Dec 3, 2008, at 1:00 PM, Christopher Barker wrote:

>> for more than one space between numbers, like:
>>
>> 1  2  3  4   5
>> 6  7  8  9  10
> 
> 
> On the version I'm working on, both delimiter='' and delimiter=None  
> (default) would give you the expected output.

so empty string and None both mean "any white space"? also tabs, etc?

> delimiter=' ' would  fail,

s only exactly that delimiter.

Is that so things like '\t' will work right?

but what about:

4,  5, 34,123, ....

In that case, ',' is the delimiter, but whitespace is ignored.
or

4\t  5\t 34\t  123.

we're ignoring extra whitespace there, too, so I'm not sure why we 
shouldn't ignore it in the ' ' case also.

  delimiter='  ' would work.

but in my example, there were sometimes two spaces, sometimes three -- 
so I think it would fail, no?
 >>> "1  2  3  4   5".split('  ')
['1', '2', '3', '4', ' 5']

actually, that would work, but four spaces wouldn't.

 >>> "1  2  3  4    5".split('  ')
['1', '2', '3', '4', '', '5']

I guess the solution is to use delimiter=None in that case, and is does 
make sense that you can't have ' ' mean "one or more spaces", but "\t" 
mean "only one tab".

-Chris



-- 
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker@noaa.gov


More information about the Numpy-discussion mailing list