Exemple #1
0
def globals_from_file(filename):
    _file = open(filename)
    data  = tokenize.untokenize(translate(_file.readline))
    compiled = compile(data, filename, "exec")
    globals_ = {}
    exec(compiled, globals_)
    return globals_
Exemple #2
0
def globals_from_file(filename):
    # be aware of same file path for relative imports
    old_path0   = sys.path[0]
    sys.path[0] = os.path.dirname(filename)

    _file = open(filename)
    data  = tokenize.untokenize(translate(_file.readline))
    compiled = compile(data, filename, "exec")
    globals_ = {}
    exec(compiled, globals_)

    # restore the original sys.path
    sys.path[0] = old_path0
    return globals_, data
Exemple #3
0
def globals_from_file(filename):
    # be aware of same file path for relative imports
    old_path0 = sys.path[0]
    sys.path[0] = os.path.dirname(filename)

    _file = open(filename)
    data = tokenize.untokenize(translate(_file.readline))
    compiled = compile(data, filename, "exec")
    globals_ = {}
    exec(compiled, globals_)

    # restore the original sys.path
    sys.path[0] = old_path0
    return globals_, data