You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
606 B

import os
import time
import hashlib
from itertools import dropwhile
import sys
import tempfile
sys.path.append(os.path.dirname(__file__))
def load(module_source):
descriptor, tmpfilepath = tempfile.mkstemp(suffix='.py')
tmpfiledir = os.path.dirname(tmpfilepath)
tmpfilename = os.path.splitext(os.path.split(tmpfilepath)[-1])[0]
sys.path.append(tmpfiledir)
try:
with open(tmpfilepath, 'w') as f:
f.write(module_source)
return __import__(tmpfilename)
finally:
os.close(descriptor)
os.remove(tmpfilepath)
if __name__ == '__main__':
pass