[Tutor] string on multiple lines

Magnus Lycka magnus@thinkware.se
Wed Nov 13 18:23:04 2002


At 14:39 2002-11-13 -0800, Scott Widney wrote:
>Before you compare the strings, remove any unnecessary data (in this case
>the strings).
>
>def clean(dirtyString):
>     '''New and Improved!'''
>     return "".join(dirtyString.split())

Let's try that...

 >>> def clean(dirty): return "".join(dirty.split())
...
 >>> a = ' "this is a field",     "this is another field" '
 >>> b = '"this is a field","this is another field"'
 >>> clean(a) == clean(b)
1

So far so good

 >>> c = '"thisisafield","thisisanotherfield"'
 >>> clean(a) == clean(c)
1

:( You don't want this, do you? What is the the purpose
of the double quotes? Aren't they there to indicate that
the whitespace inside them matters?

If the purpose is to handle typical delimited files,
such as comma separated value (CSV) files, don't
reinvent that once more please. There are at least
three python modules out there on the net, called
ASV, CSV and DSV. We don't need BSV as well! ;)

Pick one which is already there (and probably tried
and tested as well):
http://www.object-craft.com.au/projects/csv/
http://sourceforge.net/projects/python-dsv/
http://tratt.net/laurie/python/asv/

I wish one of these would be in the standard library,
since it's a very common thing to do, but it seems
Guido don't want that...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se