python类execfile()的实例源码

misc.py 文件源码 项目:hakkuframework 作者: 4shadoww 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:islam-buddy 作者: hamir 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:FightstickDisplay 作者: calexil 项目源码 文件源码 阅读 63 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:cryptogram 作者: xinmingzhang 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:UMOG 作者: hsab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:beepboop 作者: nicolehe 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:hackathon 作者: vertica 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
misc.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def execfile(filename, myglobals=None, mylocals=None):
        """
        Read and execute a Python script from a file in the given namespaces.
        The globals and locals are dictionaries, defaulting to the current
        globals and locals. If only globals is given, locals defaults to it.
        """
        if myglobals is None:
            # There seems to be no alternative to frame hacking here.
            caller_frame = inspect.stack()[1]
            myglobals = caller_frame[0].f_globals
            mylocals = caller_frame[0].f_locals
        elif mylocals is None:
            # Only if myglobals is given do we set mylocals to it.
            mylocals = myglobals
        if not isinstance(myglobals, Mapping):
            raise TypeError('globals must be a mapping')
        if not isinstance(mylocals, Mapping):
            raise TypeError('locals must be a mapping')
        with open(filename, "rbU") as fin:
             source = fin.read()
        code = compile(source, filename, "exec")
        exec_(code, myglobals, mylocals)
py3compat.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.
py3compat.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            loc = loc if (loc is not None) else glob
            scripttext = builtin_mod.open(fname).read()+ '\n'
            # compile converts unicode filename to str assuming
            # ascii. Let's do the conversion before calling compile
            if isinstance(fname, unicode):
                filename = unicode_to_str(fname)
            else:
                filename = fname
            compiler = compiler or compile
            exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            if isinstance(fname, unicode):
                filename = fname.encode(sys.getfilesystemencoding())
            else:
                filename = fname
            where = [ns for ns in [glob, loc] if ns is not None]
            if compiler is None:
                builtin_mod.execfile(filename, *where)
            else:
                scripttext = builtin_mod.open(fname).read().rstrip() + '\n'
                exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.
py3compat.py 文件源码 项目:leetcode 作者: thomasyimgit 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            loc = loc if (loc is not None) else glob
            scripttext = builtin_mod.open(fname).read()+ '\n'
            # compile converts unicode filename to str assuming
            # ascii. Let's do the conversion before calling compile
            if isinstance(fname, unicode):
                filename = unicode_to_str(fname)
            else:
                filename = fname
            compiler = compiler or compile
            exec(compiler(scripttext, filename, 'exec'), glob, loc)
ipython_py3compat.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None):
        loc = loc if (loc is not None) else glob
        exec compile(open(fname, 'rb').read(), fname, 'exec') in glob, loc

    # Refactor print statements in doctests.
ipython_py3compat.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def MethodType(func, instance):
        return types.MethodType(func, instance, type(instance))

    # don't override system execfile on 2.x:
ipython_py3compat.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None):
            loc = loc if (loc is not None) else glob
            # The rstrip() is necessary b/c trailing whitespace in files will
            # cause an IndentationError in Python 2.6 (this was fixed in 2.7,
            # but we still support 2.6).  See issue 1027.
            scripttext = __builtin__.open(fname).read().rstrip() + '\n'
            # compile converts unicode filename to str assuming
            # ascii. Let's do the conversion before calling compile
            if isinstance(fname, unicode):
                filename = unicode_to_str(fname)
            else:
                filename = fname
            exec compile(scripttext, filename, 'exec') in glob, loc
ipython_py3compat.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def execfile(fname, *where):
            if isinstance(fname, unicode):
                filename = fname.encode(sys.getfilesystemencoding())
            else:
                filename = fname
            __builtin__.execfile(filename, *where)
py3compat.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.
py3compat.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            loc = loc if (loc is not None) else glob
            scripttext = builtin_mod.open(fname).read()+ '\n'
            # compile converts unicode filename to str assuming
            # ascii. Let's do the conversion before calling compile
            if isinstance(fname, unicode):
                filename = unicode_to_str(fname)
            else:
                filename = fname
            compiler = compiler or compile
            exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            if isinstance(fname, unicode):
                filename = fname.encode(sys.getfilesystemencoding())
            else:
                filename = fname
            where = [ns for ns in [glob, loc] if ns is not None]
            if compiler is None:
                builtin_mod.execfile(filename, *where)
            else:
                scripttext = builtin_mod.open(fname).read().rstrip() + '\n'
                exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.
py3compat.py 文件源码 项目:Repobot 作者: Desgard 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            if isinstance(fname, unicode):
                filename = fname.encode(sys.getfilesystemencoding())
            else:
                filename = fname
            where = [ns for ns in [glob, loc] if ns is not None]
            if compiler is None:
                builtin_mod.execfile(filename, *where)
            else:
                scripttext = builtin_mod.open(fname).read().rstrip() + '\n'
                exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.
py3compat.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            loc = loc if (loc is not None) else glob
            scripttext = builtin_mod.open(fname).read()+ '\n'
            # compile converts unicode filename to str assuming
            # ascii. Let's do the conversion before calling compile
            if isinstance(fname, unicode):
                filename = unicode_to_str(fname)
            else:
                filename = fname
            compiler = compiler or compile
            exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            if isinstance(fname, unicode):
                filename = fname.encode(sys.getfilesystemencoding())
            else:
                filename = fname
            where = [ns for ns in [glob, loc] if ns is not None]
            if compiler is None:
                builtin_mod.execfile(filename, *where)
            else:
                scripttext = builtin_mod.open(fname).read().rstrip() + '\n'
                exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.
py3compat.py 文件源码 项目:blender 作者: gastrodia 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def execfile(fname, glob=None, loc=None, compiler=None):
            loc = loc if (loc is not None) else glob
            scripttext = builtin_mod.open(fname).read()+ '\n'
            # compile converts unicode filename to str assuming
            # ascii. Let's do the conversion before calling compile
            if isinstance(fname, unicode):
                filename = unicode_to_str(fname)
            else:
                filename = fname
            compiler = compiler or compile
            exec(compiler(scripttext, filename, 'exec'), glob, loc)
py3compat.py 文件源码 项目:yatta_reader 作者: sound88 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def execfile(fname, glob, loc=None, compiler=None):
        loc = loc if (loc is not None) else glob
        with open(fname, 'rb') as f:
            compiler = compiler or compile
            exec(compiler(f.read(), fname, 'exec'), glob, loc)

    # Refactor print statements in doctests.


问题


面经


文章

微信
公众号

扫码关注公众号