[Tutor] Parsing suggestion? (CUE file)
Terry Carroll
carroll at tjc.com
Tue Feb 3 21:26:22 CET 2009
On Tue, 3 Feb 2009, Kent Johnson wrote:
> On Tue, Feb 3, 2009 at 2:55 PM, Terry Carroll <carroll at tjc.com> wrote:
>
> > The silver cloud to my temporary Internet outage was that I was able to
> > solve my problem, in the process discovering that the csv module can parse
> > a CUE file[1] quite nicely if you set up an appropriate csv.Dialect class.
> >
> > [1] http://en.wikipedia.org/wiki/Cue_file
>
> What is the dialect? That sounds like a useful trick.
This seems to be working for me, at least with the sample CUE files I've
tested with so far:
###############################################################
import csv
class cue(csv.Dialect):
"""Describe the usual properties of CUE files."""
delimiter = ' '
quotechar = '"'
doublequote = True
skipinitialspace = True
lineterminator = '\r\n'
quoting = csv.QUOTE_MINIMAL
csv.register_dialect("cue", cue)
f = open("test.cue", "r")
reader = csv.reader(f,dialect="cue")
for row in reader:
print row
###############################################################
The dialect is the same as the standard excel dialect, which I cribbed out
of csv.py, except for delimiter and skipinitialspace.
My project is to write a program to convert a CUE file into a list of
labels that can be imported into Audacity; and perhaps a file of ID3 info
that can be imported into MP3 tagging software. If I had to parse the
blank-separated fields of quoted text that included blanks, I don't know
how long this would have taken me.
More information about the Tutor
mailing list