[EMAIL PROTECTED] wrote: > Hello everybody, I'm new to python (...I work with cobol...) > > I have to parse a file (that is a dbIII file) whose stucture look like > this: > |string|, |string|, |string that may contain commas inside|, 1, 2, 3, | > other string|
There are a number of relatively simple options that come to mind, including regular expressions: ##### BEGIN CODE ##### import re # # dbIII.txt: # |string|, |string|, |string|, |string|, |,1,2,3,4|, |other string| # handle = open('dbIII.txt') for line in handle.xreadlines(): for match in re.finditer(r'\|\s*([^|]+)\s*\|,*', line): for each in match.groups(): print each handle.close() ##### END CODE ##### Without knowing what you need to do with the data, it's hard to suggest a better method for parsing it. The above should work, provided that the data is always in the format | data | with no pipe symbols in between the ones used as separators. HTH, -Jay -- http://mail.python.org/mailman/listinfo/python-list