This seems to crash my program and gives me errors on the #include statements
Eric_Dexter at msn.com
Eric_Dexter at msn.com
Mon Sep 4 09:07:59 EDT 2006
I was trying to add this to my project but I must be missing some
includes or there is a serius error somewhere
Anthra Norell wrote:
> Dexter,
> Here's a function that screens out all instrument blocks and puts them into a dictionary keyed on the instrument number:
> --------------------------------------------
> def get_instruments (file_name):
> INSIDE = 1
> OUTSIDE = 0
> f = file (file_name, 'ra')
> state = OUTSIDE
> instruments = {}
> instrument_segment = ''
> for line in f:
> if state == OUTSIDE:
> if line.startswith ('<CsInstruments'):
> state = INSIDE
> instrument_segment += line
> else:
> instrument_segment += line
> if line.lstrip ().startswith ('instr'):
> instrument_number = line.split () [1]
> elif line.startswith ('</CsInstruments'):
> instruments [instrument_number] = instrument_segment
> instrument_segment = ''
> state = OUTSIDE
> f.close ()
> return instruments
> ------------------------------------------------
> You have received good advice on using parsers: "beautiful soup" or "pyparse". These are powerful tools capable of doing complicated
> extractions. Yours is not a complicated extraction. Simon tried it with "beautiful soup". That seems simple enough, though he finds
> the data by index leaving open where he gets the index from. There's surely a way to get the data by name.
> Contrary to the parser the function will miss if tags take liberties with upper-lower case letters as they are probably
> allowed by the specification. A regular expression might have to be used, if they do.
> From your description I haven't been able to infer what the final format of your data is supposed to be. So I cannot tell you
> how to go on from here. You'll find out. If not, just keep asking.
> The SE solution which you said couldn't work out would be the following. It makes the same dictionary the function makes and it is
> case-insensitive:
> ------------------------------------------------
> >>> Instrument_Segment_Filter = SE.SE ('<EAT> "~(?i)<CsInstruments>(.|\n)*?</CsInstruments>~==\n\n" ')
> >>> instrument_segments= Instrument_Segment_Filter ('file_name', '')
> >>> print instrument_segments
> (... see all instrument segments ...)
> >>> Instrument_Number = SE.SE ('<EAT> ~instr.*~==\n')
> >>> instruments ={}
> >>> for segment in instrument_segments.split ('\n\n'):
> if segment:
> instr_line = Instrument_Number (segment)
> instrument_number = instr_line.split ()[1]
> instruments [instrument_number] = segment
> --------------------------------------------------
> (If you're on Windows and the CRs bother you, take them out with an additional definition when you make your
> Instrument_Block_Filter: (13)= or "\r=")
> Regards
> Frederic
> ----- Original Message -----
> From: <Eric_Dex... at msn.com>
> Newsgroups: comp.lang.python
> To: <python-l... at python.org>
> Sent: Wednesday, August 30, 2006 1:51 AM
> Subject: Re: newbe question about removing items from one file to another file
> > 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>
> ...
> etc.
I cut and pasted this.. It seems to be crashing my program.. I am not
sure that I have all the right imports.. seems to be fine when I go to
an older version of the file... I uploaded it onto source forge.
https://sourceforge.net/project/showfiles.php?group_id=156455&package...
http://www.dexrow.com
More information about the Python-list
mailing list