f=open("bar.txt") import imp fs=imp.new_module("fs") exec f in fs.__dict__ .... rests are the same althought why use anything other than .py, when you import .py, it get compiled into .pyc and it load faster next time