Avoid format() with locals()
Substitute os.path.relpath() for transplant()
Use dictionaries instead of Record type; add Module class
Only open file if it is to be used