string / split method on ASCII code?
python.list at tim.thechases.com
Wed Mar 12 21:55:56 CET 2008
> I have these annoying textilfes that are delimited by the ASCII char for <<
> (only its a single character) and >> (again a single character)
> Their codes are 174 and 175, respectively.
> My datafiles are in the moronic form
> I need to split on those freaking characters. Any tips on how to make split
> work with these things?
If it were a single character, you could just use
However, since you need to split on multiple characters, you can use
splitter_re = re.compile(chr(174) + '|' + chr(175))
for line in file(FILENAME):
parts = splitter_re.split(line)
and then go find a large blunt object with which to bludgeon the
creator of the file... :)
They aren't exactly ascii characters (0-127), but the above
should at least do the trick.
More information about the Python-list