Parsing text
Stefan Behnel
stefan_ml at behnel.de
Wed May 6 15:05:04 EDT 2009
iainemsley wrote:
> for scene in text.split('Scene'):
> num = re.compile("^\s\[0-9, i{1,4}, v]", re.I)
> textNum = num.match(scene)
Not related to your problem, but to your code - I'd write this as follows:
match_scene_num = re.compile("^\s\[0-9, i{1,4}, v]", re.I).match
for scene_section in text.split('Scene'):
text_num = match_scene_num(scene_section)
This makes the code more readable and avoids unnecessary work inside the loop.
Stefan
More information about the Python-list
mailing list