On Tue, Feb 3, 2009 at 3:26 PM, Terry Carroll <carr...@tjc.com> wrote: > On Tue, 3 Feb 2009, Kent Johnson wrote: > >> On Tue, Feb 3, 2009 at 2:55 PM, Terry Carroll <carr...@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.
Ah, I see. I imagined something more ambitious, that treated the lines as fields. You are using csv to do kind of a smart split() function. > 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. I would look at pyparsing for that, and make sure cuetools won't do what you want. Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor