June 2002
Beginner to intermediate
640 pages
14h 24m
English
A third-party vendor I (Rick Hightower) worked with once had a problem reading the IDL files we were trying to integrate with its product. Specifically it didn't like identifiers beginning with ::, as in ::com::mycompany::Employee, preferring com::mycompany::Employee. My job was to convert the IDL files to their liking, which I did using regular expressions. The code I wrote to do this is just four lines long (actually six but four with a little cheating).
Here's the code to read in the file and write all the replacement text:
f=open(filename) fstr=re.compile(r'\s((::)(\w+))\b').sub(r' \3', f.read()) f.close(); f=open(filename, "w") f.write(fstr); f.close()
Here's the complete fixIDL() function:
import re def fixIDL(filename): ...
Read now
Unlock full access