[Numpy-discussion] More loadtxt() changes

Ryan May rmay31 at gmail.com
Wed Nov 26 17:51:11 EST 2008


John Hunter wrote:
> On Tue, Nov 25, 2008 at 11:23 PM, Ryan May <rmay31 at gmail.com> wrote:
> 
>> Updated patch attached.  This includes:
>>  * Updated docstring
>>  * New tests
>>  * Fixes for previous issues
>>  * Fixes to make new tests actually work
>>
>> I appreciate any and all feedback.
> 
> I'm having trouble applying your patch, so I haven't tested yet, but
> do you (and do you want to) handle a case like this::
> 
>     from  StringIO import StringIO
>     import matplotlib.mlab as mlab
>     f1 = StringIO("""\
>     name   age  weight
>     John   23   145.
>     Harry  43   180.""")
> 
>     for line in f1:
>         print line.split(' ')
> 
> 
> Ie, space delimited but using an irregular number of spaces?   One
> place this comes up a lot is when  the output files are actually
> fixed-width using spaces to line up the columns.  One could count the
> columns to figure out the fixed widths and work with that, but it is
> much easier to simply assume space delimiting and handle the irregular
> number of spaces assuming one or more spaces is the delimiter.  In
> csv2rec, we write a custom file object to handle this case.
> 
> Apologies if you are already handling this and I missed it...

I think line.split(None) handles this case, so *in theory* passing 
delimiter=None would do it.  I *am* interested in this case, so I'll 
have to give it a try when I get a chance. (I sense this is the same 
case as Manuel just asked about.)

Ryan

-- 
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma



More information about the NumPy-Discussion mailing list