[Tutor] re.match enigma
Johannes Graumann
graumann at caltech.edu
Wed Jan 7 22:46:13 EST 2004
Hello,
Wrote this snippet:
for counter in range(0,len(ms2_data[spectrum]['spectrum'])):
try:
re.match(r"^[\d\.]+",spectrum_data)
except:
spectrum_data = \LINEBREAK
string.join(ms2_data[spectrum]['spectrum'][counter],'|') else:
spectrum_data = \LINEBREAK
string.join([spectrum_data,string.join(ms2_data[spectrum]['spectrum'][c
ounter],'|')],'#')
Which is supposed to give me a data string, where members of a pair
(which originally come from a group) are separated by '|' and subsequent
pairs are delimited by '#'.
This does what I want UNLESS the 'spectrum_data' variable is emptied to
spectrum_data =''
somewhere further on in the 'for counter' loop. In this case no except
occurs, even though 'spectrum_data' does neither start with a digit (\d)
nor with a comma - it's empty!
What am I doing?
Confused, Joh
More information about the Tutor
mailing list