Newbie: Working with large database -- help!

Mark McEahern marklists at mceahern.com
Tue Apr 30 21:56:54 EDT 2002


[Owen Marshall]
> I am trying to work with a file -- for lack of better terms, a
> database. The data is like this:
>
> data|data|data|data

Short answer:  split() -- a method of the string object -- is your friend.

Demo:

>>> s = "a|b|c|d|e"
>>> delim = "|"
>>> a = s.split(delim)
>>> a
['a', 'b', 'c', 'd', 'e']

What if one of the fields itself has a pipe in it?  Presumably, the writer
escapes those into something other than a pipe.

Cheers,

// m






More information about the Python-list mailing list