split encloser
John Machin
sjmachin at lexicon.net
Fri Apr 4 03:38:39 EST 2003
aussie2010 at yahoo.com (Chris) wrote in message news:<435d40e0.0304031530.1c197742 at posting.google.com>...
> string.split() takes a delimiter and works fine as long as the
> delimiter isn't part of the data fields. But frequently they are.
> e.g. 'John Doe,135 South Main St.,#122, Springfield, Iowa' or
> ' so long goodbye see ya'
>
> Because the fields can contain the delimiter in some cases, an
> encloser is usually used (typically "") to handle those fields.
>
> The above strings would be written:
> 'John Doe,"135 South Main St., #122", Springfield, Iowa'
> and
> '"so long" goodbye "see ya"'
>
> I don't understand regular expressions but I was wondering if anyone
> that did knew of a way to get re.split() to handle "enclosers" as used
> above.
Aussie cobber,
REs are about as useful as a hip pocket on a singlet when it comes to
data that includes the "encloser" as well. For example in a database,
yer old Auntie Mabel's address_line_1 might be
"Emoh Ruo", 123 Smith St
but would appear as
"""Emoh Ruo"", 123 Smith St"
in an exported file (or it should).
Get onta Dave Cole's you-beaut CSV module at:
http://www.object-craft.com.au/projects/csv/
Cheerio,
John
More information about the Python-list
mailing list