Re: [Tutor] Parsing suggestion? (CUE file) -- identify result
Le Tue, 3 Feb 2009 17:36:41 -0500, Kent Johnson ken...@tds.net a écrit : I think your use of the csv module is fine. What I really meant to say was more like, I would have looked to pyparsing to solve the same problem, and if you want a parser that parses the file into meaningful records, then it might still be worth a look. This would require heavy use of the setResultsName() method to attach semantic tags to the parse results; so that when you dig into them you know what each snippet is -- without the need of partial reparsing ;-) The point can be illustrated with the simple case of parsing arithmetic operations. Imagine each operand of a '+' can be a (litteral) number, a symbol (name), a grouped (parenthesized) sub-operation, an operation of higher priority. The result beeing of the form [op1, '+', op2] There is no other way to know what kind of thing op1 and op2 are, if they don't themselves carry the information, than re-examining them. Which has already beeing done while parsing. (The information needed is the name of the parsing rule used to yield the result.) Denis Kent -- la vida e estranya ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Parsing suggestion? (CUE file)
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. Comma Separated Values; it's not just for commas any more. [1] http://en.wikipedia.org/wiki/Cue_file What is the dialect? That sounds like a useful trick. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Parsing suggestion? (CUE file)
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
Re: [Tutor] Parsing suggestion? (CUE file)
On Tue, Feb 3, 2009 at 5:17 PM, Terry Carroll carr...@tjc.com wrote: On Tue, 3 Feb 2009, Kent Johnson wrote: I would look at pyparsing for that, and make sure cuetools won't do what you want. csv seems to be working well for me, and it's a standard piece of Python, which I prefer to use. I don't think I'm twisting it out of its intended useh: despite its name, it's really about splitting up uniform delimited input lines. The ability to use other delimeters and to trim the left-padding seems consistent with my use of it. I think your use of the csv module is fine. What I really meant to say was more like, I would have looked to pyparsing to solve the same problem, and if you want a parser that parses the file into meaningful records, then it might still be worth a look. If we talk about it enough, maybe Paul McGuire will contribute the parser :-) Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Parsing suggestion? (CUE file)
On Tue, 3 Feb 2009, Kent Johnson wrote: Ah, I see. I imagined something more ambitious, that treated the lines as fields. I find that the more ambitious my projects become, the less likely I am to complete them! With two toddlers, on a good day, I get 30 to 60 minutes of discretionary time, some of which I can do some coding! You are using csv to do kind of a smart split() function. That's an excellent summary. I would look at pyparsing for that, and make sure cuetools won't do what you want. csv seems to be working well for me, and it's a standard piece of Python, which I prefer to use. I don't think I'm twisting it out of its intended useh: despite its name, it's really about splitting up uniform delimited input lines. The ability to use other delimeters and to trim the left-padding seems consistent with my use of it. The time it took between thinking of using CSV and getting it to actually work was probably a lot less time than I would have spend downloading and installing pyparsing, and figuring out how it worked. Thanks for the cuetools tip. I hadn't heard of it before. I spent some time looking for tools related to Audacity and CUE files, and couldn't find much (apart from one forum posting pointing out that Audacity didn't support CUE files, but it would be pretty easy to convert a CUE file to an Audacity label file). ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] Parsing suggestion? (CUE file)
I am parsing certai ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Parsing suggestion? (CUE file)
On Tue, 3 Feb 2009, Terry Carroll wrote: I am parsing certai Sorry about that. I was composing this message last night when my Internet connection went down. When I logged on this morning, I had a partial message. I meant to cancel but unfortunately, in pine, the SEND key (CTRL-X) is adjacent to the CANCEL key (CTRL-C), and I hit the wrong one. 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. Comma Separated Values; it's not just for commas any more. [1] http://en.wikipedia.org/wiki/Cue_file ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Parsing suggestion? (CUE file)
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. 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. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor