summaryrefslogtreecommitdiff
path: root/python/helpers/pydev/_pydev_imps/_pydev_execfile.py
blob: 954783c8d0854f418aa7df3790f083a498c26543 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#We must redefine it in Py3k if it's not already there
def execfile(file, glob=None, loc=None):
    if glob is None:
        import sys
        glob = sys._getframe().f_back.f_globals
    if loc is None:
        loc = glob

    # It seems that the best way is using tokenize.open(): http://code.activestate.com/lists/python-dev/131251/
    import tokenize
    stream = tokenize.open(file)
    try:
        contents = stream.read()
    finally:
        stream.close()

    #execute the script (note: it's important to compile first to have the filename set in debug mode)
    exec(compile(contents+"\n", file, 'exec'), glob, loc)