Python __builtin__ 模块,execfile() 实例源码

我们从Python开源项目中,提取了以下34个代码示例,用于说明如何使用__builtin__.execfile()

项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
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)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
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)
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
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)
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
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)
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
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)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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)
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
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)
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
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)
项目:hackathon    作者:vertica    | 项目源码 | 文件源码
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)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
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.
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
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)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
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)
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
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.
项目:leetcode    作者:thomasyimgit    | 项目源码 | 文件源码
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)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
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.
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def MethodType(func, instance):
        return types.MethodType(func, instance, type(instance))

    # don't override system execfile on 2.x:
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
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
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def execfile(fname, *where):
            if isinstance(fname, unicode):
                filename = fname.encode(sys.getfilesystemencoding())
            else:
                filename = fname
            __builtin__.execfile(filename, *where)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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.
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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.
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
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)
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
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.
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
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)
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
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)
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
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.
项目:blender    作者:gastrodia    | 项目源码 | 文件源码
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)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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.
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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.
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
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)