[EMAIL PROTECTED] wrote: > Anthra Norell wrote: > > Dexter, > > > > I looked at the format specification. It contains an example: > > > > ----------------------------------------------- > > > > <CsoundSynthesizer>; > > ; test.csd - a Csound structured data file > > > > <CsOptions> > > -W -d -o tone.wav > > </CsOptions> > > > > <CsVersion> ;optional section > > Before 4.10 ;these two statements check for > > After 4.08 ; Csound version 4.09 > > </CsVersion> > > > > <CsInstruments> > > ; originally tone.orc > > sr = 44100 > > kr = 4410 > > ksmps = 10 > > nchnls = 1 > > instr 1 > > a1 oscil p4, p5, 1 ; simple oscillator > > out a1 > > endin > > </CsInstruments> > > > > <CsScore> > > ; originally tone.sco > > f1 0 8192 10 1 > > i1 0 1 20000 1000 ;play one second of one kHz tone > > e > > </CsScore> > > > > </CsoundSynthesizer> > > > > ------------------------------------- > > > > If I understand correctly you want to write the instruments block to a file > > (from <CsInstruments> to </CsInstruments>)? Right? Or > > each block to its own file in case there are several?. You want your code > > to generate the file names? Can you confirm this or > > explain it differently? > > > > Regards > > > > Frederic > > > > > > ----- Original Message ----- > > From: <[EMAIL PROTECTED]> > > Newsgroups: comp.lang.python > > To: <python-list@python.org> > > Sent: Monday, August 28, 2006 10:48 AM > > Subject: Re: newbe question about removing items from one file to another > > file > > > > > > > > > > Anthra Norell wrote: > > > > Eric, > > > > Having played around with problems of this kind for quite some time > > > > I find them challenging even if I don't really have time > > to > > > > get sidetracked. Your description of the problem makes it all the more > > > > challenging, because its 'expressionist' quality adds the > > > > challenge of guessing what you mean. > > > > I'd like to take a look at your data, if you would post a segment on > > > > which to operate, the same data the way it should look > > in > > > > the end. In most cases this is pretty self-explanatory. Explain the > > > > points that might not be obvious to a reader who knows > > nothing > > > > about your mission. > > > > > > > > Frederic > > > > > > > > ----- Original Message ----- > > > > From: <[EMAIL PROTECTED]> > > > > Newsgroups: comp.lang.python > > > > To: <python-list@python.org> > > > > Sent: Sunday, August 27, 2006 11:35 PM > > > > Subject: newbe question about removing items from one file to another > > > > file > > > > > > > > > > > > > def simplecsdtoorc(filename): > > > > > file = open(filename,"r") > > > > > alllines = file.read_until("</CsInstruments>") > > > > > pattern1 = re.compile("</") > > > > > orcfilename = filename[-3:] + "orc" > > > > > for line in alllines: > > > > > if not pattern1 > > > > > print >>orcfilename, line > > > > > > > > > > I am pretty sure my code isn't close to what I want. I need to be > > > > > able > > > > > to skip html like commands from <defined> to <undefined> and to key on > > > > > another word in adition to </CsInstruments> to end the routine > > > > > > > > > > I was also looking at se 2.2 beta but didn't see any easy way to use > > > > > it > > > > > for this or for that matter search and replace where I could just add > > > > > it as a menu item and not worry about it. > > > > > > > > > > thanks for any help in advance > > > > > > > > > > -- > > > > > http://mail.python.org/mailman/listinfo/python-list > > > > > > sorry about that this is a link to a discription of the format > > > http://kevindumpscore.com/docs/csound-manual/commandunifile.html > > > It is possible to have more than one instr defined in an .csd file so I > > > would need to look for that string also if I want to seperate the > > > instruments out. > > > > > > http://www.dexrow.com > > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > I need to take it between the blocks only I also need to make sure I > only take one instrument > defined in this example with the code instr 1 I also need the code > > <CsInstruments> > > ; originally tone.orc > > sr = 44100 > > kr = 4410 > > ksmps = 10 > > nchnls = 1 > > regardless of what instrument I take. The function would have to > except the instrument number as an argument > > http://www.dexrow.com
Using BeautifulSoup and the interactive interpreter, I figured out the following script in about 15 minutes: # s is a string containing the example file from above. from BeautifulSoup import BeautifulStoneSoup soup = BeautifulStoneSoup(s) csin = soup.contents[0].contents[5] lines = csin.string.splitlines() print csin.string It prints: ; originally tone.orc sr = 44100 kr = 4410 ksmps = 10 nchnls = 1 instr 1 a1 oscil p4, p5, 1 ; simple oscillator out a1 endin and of course you could say "lines = csin.string.splitlines()" to get a list of the lines. That doesn't take you all the way, but it's something. Hope that helps, Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list