[Numpy-discussion] More loadtxt() changes

John Hunter jdh2358@gmail....
Wed Nov 26 09:52:59 CST 2008


On Tue, Nov 25, 2008 at 11:23 PM, Ryan May <rmay31@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...

JDH


More information about the Numpy-discussion mailing list