"Jia Lu" <[EMAIL PROTECTED]> writes: > I wonder if I can import a file with other file extensions ?
I use this function in most of my test infrastructures, to import programs as modules for unit testing. def make_module_from_file(module_name, file_name): """ Make a new module object from the code in specified file """ from types import ModuleType module = ModuleType(module_name) module_file = open(file_name, 'r') exec module_file in module.__dict__ return module -- \ "Men never do evil so completely and cheerfully as when they do | `\ it from religious conviction." -- Blaise Pascal (1623-1662), | _o__) Pense'es, #894. | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list