input record seperator (equivalent of "$|" of perl)

Nick Coghlan ncoghlan at
Mon Dec 20 11:16:55 CET 2004

les_ander at wrote:
> I would like to read this file as a record.
> I can do this in perl by defining a record seperator;
> is there an equivalent in python? 

Depending on your exact use case, you may also get some mileage out of using the 
csv module with a custom delimeter.

Py> from csv import reader
Py> parsed = reader(demo, delimiter='|')
Py> for line in parsed: print line
['a', 'b', 'c', 'd']
['1', '2', '3', '4']


P.S. 'demo' was created via:
Py> from tempfile import TemporaryFile
Py> demo = TemporaryFile()
Py> demo.write(txt)

Nick Coghlan   |   ncoghlan at   |   Brisbane, Australia

More information about the Python-list mailing list