diff options
author | Neal Norwitz <nnorwitz@gmail.com> | 2007-08-12 00:43:29 (GMT) |
---|---|---|
committer | Neal Norwitz <nnorwitz@gmail.com> | 2007-08-12 00:43:29 (GMT) |
commit | 016880229a369a3fb419f3eed28b6db7c342fe71 (patch) | |
tree | 9b11de5c197bc556dd515e035327673765cd4871 /Doc | |
parent | 41eaedd3613cebc83e6b9925499369992c7a7770 (diff) | |
download | cpython-016880229a369a3fb419f3eed28b6db7c342fe71.zip cpython-016880229a369a3fb419f3eed28b6db7c342fe71.tar.gz cpython-016880229a369a3fb419f3eed28b6db7c342fe71.tar.bz2 |
Kill execfile(), use exec() instead
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/dist/dist.tex | 2 | ||||
-rw-r--r-- | Doc/howto/doanddont.tex | 6 | ||||
-rw-r--r-- | Doc/lib/libdoctest.tex | 2 | ||||
-rw-r--r-- | Doc/lib/libexcs.tex | 2 | ||||
-rw-r--r-- | Doc/lib/libfuncs.tex | 31 | ||||
-rw-r--r-- | Doc/lib/libuser.tex | 2 | ||||
-rw-r--r-- | Doc/ref/ref4.tex | 7 | ||||
-rw-r--r-- | Doc/ref/ref6.tex | 7 | ||||
-rw-r--r-- | Doc/tut/tut.tex | 14 |
9 files changed, 22 insertions, 51 deletions
diff --git a/Doc/dist/dist.tex b/Doc/dist/dist.tex index ff5106a..a33227f 100644 --- a/Doc/dist/dist.tex +++ b/Doc/dist/dist.tex @@ -2290,7 +2290,7 @@ This is useful if you need to find out the distribution meta-data (passed as keyword args from \var{script} to \function{setup()}), or the contents of the config files or command-line. -\var{script_name} is a file that will be run with \function{execfile()} +\var{script_name} is a file that will be read and run with \function{exec()} \code{sys.argv[0]} will be replaced with \var{script} for the duration of the call. \var{script_args} is a list of strings; if supplied, \code{sys.argv[1:]} will be replaced by \var{script_args} for the duration diff --git a/Doc/howto/doanddont.tex b/Doc/howto/doanddont.tex index 0cd5d91..b54f069 100644 --- a/Doc/howto/doanddont.tex +++ b/Doc/howto/doanddont.tex @@ -81,7 +81,7 @@ There are situations in which \code{from module import *} is just fine: \end{itemize} -\subsection{Unadorned \function{exec}, \function{execfile} and friends} +\subsection{Unadorned \function{exec} and friends} The word ``unadorned'' refers to the use without an explicit dictionary, in which case those constructs evaluate code in the {\em current} environment. @@ -97,7 +97,7 @@ Bad examples: >>> def func(s, **kw): >>> for var, val in kw.items(): >>> exec("s.%s=val" % var) # invalid! ->>> execfile("handler.py") +>>> exec(open("handler.py").read()) >>> handle() \end{verbatim} @@ -111,7 +111,7 @@ Good examples: >>> for var, val in kw.items(): >>> setattr(s, var, val) >>> d={} ->>> execfile("handle.py", d, d) +>>> exec(open("handler.py").read(), d, d) >>> handle = d['handle'] >>> handle() \end{verbatim} diff --git a/Doc/lib/libdoctest.tex b/Doc/lib/libdoctest.tex index 5e28c2a..9143b84 100644 --- a/Doc/lib/libdoctest.tex +++ b/Doc/lib/libdoctest.tex @@ -1828,7 +1828,7 @@ print doctest.testsource(a, "a.f") via \function{\refmodule{pdb}.post_mortem()}, passing the traceback object from the unhandled exception. If \var{pm} is not specified, or is false, the script is run under the debugger from the start, via passing an - appropriate \function{execfile()} call to \function{\refmodule{pdb}.run()}. + appropriate \function{exec()} call to \function{\refmodule{pdb}.run()}. \versionadded{2.3} diff --git a/Doc/lib/libexcs.tex b/Doc/lib/libexcs.tex index 298f04d..74531d3 100644 --- a/Doc/lib/libexcs.tex +++ b/Doc/lib/libexcs.tex @@ -260,7 +260,7 @@ Raised when an \keyword{assert} statement fails. % XXXJH xref to these functions? Raised when the parser encounters a syntax error. This may occur in an \keyword{import} statement, in a call to the built-in functions - \function{exec()}, \function{execfile()}, \function{eval()} or + \function{exec()}, \function{eval()} or \function{input()}, or when reading the initial script or standard input (also interactively). diff --git a/Doc/lib/libfuncs.tex b/Doc/lib/libfuncs.tex index 3cc06c8..0b99c3f 100644 --- a/Doc/lib/libfuncs.tex +++ b/Doc/lib/libfuncs.tex @@ -382,15 +382,13 @@ class C: compiled passing \code{'eval'} as the \var{kind} argument. Hints: dynamic execution of statements is supported by the - \function{exec()} function. Execution of statements from a file is - supported by the \function{execfile()} function. The + \function{exec()} function. The \function{globals()} and \function{locals()} functions returns the current global and local dictionary, respectively, which may be useful to pass around for use by \function{eval()} or - \function{execfile()}. + \function{exec()}. \end{funcdesc} - \begin{funcdesc}{exec}{object\optional{, globals\optional{, locals}}} This function supports dynamic execution of Python code. \var{object} must be either a string, an open file object, or @@ -425,31 +423,6 @@ class C: argument to \function{exec()}.} \end{funcdesc} -\begin{funcdesc}{execfile}{filename\optional{, globals\optional{, locals}}} - This function is similar to the \function{exec()} function, but parses a - file given by the file name instead of a string. It - is different from the \keyword{import} statement in that it does not - use the module administration --- it reads the file unconditionally - and does not create a new module. - - The arguments are a file name and two optional dictionaries. The file is - parsed and evaluated as a sequence of Python statements (similarly to a - module) using the \var{globals} and \var{locals} dictionaries as global and - local namespace. If provided, \var{locals} can be any mapping object. - \versionchanged[formerly \var{locals} was required to be a dictionary]{2.4} - If the \var{locals} dictionary is omitted it defaults to the \var{globals} - dictionary. If both dictionaries are omitted, the expression is executed in - the environment where \function{execfile()} is called. The return value is - \code{None}. - - \warning{The default \var{locals} act as described for function - \function{locals()} below: modifications to the default \var{locals} - dictionary should not be attempted. Pass an explicit \var{locals} - dictionary if you need to see effects of the code on \var{locals} after - function \function{execfile()} returns. \function{execfile()} cannot - be used reliably to modify a function's locals.} -\end{funcdesc} - \begin{funcdesc}{file}{filename\optional{, mode\optional{, bufsize}}} Constructor function for the \class{file} type, described further in section~\ref{bltin-file-objects}, ``\ulink{File diff --git a/Doc/lib/libuser.tex b/Doc/lib/libuser.tex index 4e915a2..6dd1546 100644 --- a/Doc/lib/libuser.tex +++ b/Doc/lib/libuser.tex @@ -24,7 +24,7 @@ import user The \module{user} module looks for a file \file{.pythonrc.py} in the user's home directory and if it can be opened, executes it (using -\function{execfile()}\bifuncindex{execfile}) in its own (the +\function{exec()}\bifuncindex{exec}) in its own (the module \module{user}'s) global namespace. Errors during this phase are not caught; that's up to the program that imports the \module{user} module, if it wishes. The home directory is assumed to diff --git a/Doc/ref/ref4.tex b/Doc/ref/ref4.tex index 9ae8bfa..6ec60f8 100644 --- a/Doc/ref/ref4.tex +++ b/Doc/ref/ref4.tex @@ -19,8 +19,7 @@ block. A script file (a file given as standard input to the interpreter or specified on the interpreter command line the first argument) is a code block. A script command (a command specified on the interpreter command line with the `\strong{-c}' option) is a code -block. The file read by the built-in function \function{execfile()} -is a code block. The string argument passed to the built-in functions +block. The string argument passed to the built-in functions \function{eval()} and \function{exec()} is a code block. The expression read and evaluated by the built-in function \function{input()} is a code block. @@ -139,7 +138,7 @@ If the wild card form of import --- \samp{import *} --- is used in a function and the function contains or is a nested block with free variables, the compiler will raise a \exception{SyntaxError}. -The \function{eval()}, \function{exec()}, \function{execfile()}, +The \function{eval()}, \function{exec()}, and \function{input()} functions do not have access to the full environment for resolving names. Names may be resolved in the local and global namespaces of the caller. Free variables are not @@ -147,7 +146,7 @@ resolved in the nearest enclosing namespace, but in the global namespace.\footnote{This limitation occurs because the code that is executed by these operations is not available at the time the module is compiled.} -The \function{exec()}, \function{eval()} and \function{execfile()} +The \function{exec()} and \function{eval()} functions have optional arguments to override the global and local namespace. If only one namespace is specified, it is used for both. diff --git a/Doc/ref/ref6.tex b/Doc/ref/ref6.tex index 60e7b02..1139005 100644 --- a/Doc/ref/ref6.tex +++ b/Doc/ref/ref6.tex @@ -760,8 +760,8 @@ import __future__ [as name] That is not a future statement; it's an ordinary import statement with no special semantics or syntax restrictions. -Code compiled by calls to the builtin functions \function{exec()}, -\function{compile()} and \function{execfile()} that occur in a module +Code compiled by calls to the builtin functions \function{exec()} and +\function{compile()} that occur in a module \module{M} containing a future statement will, by default, use the new syntax or semantics associated with the future statement. This can, starting with Python 2.2 be controlled by optional arguments to @@ -811,9 +811,8 @@ string or code object supplied to the builtin \function{exec()} function does not affect the code block \emph{containing} the function call, and code contained in such a string is unaffected by \keyword{global} statements in the code containing the function call. The same applies to the -\function{eval()}, \function{execfile()} and \function{compile()} functions. +\function{eval()} and \function{compile()} functions. \bifuncindex{exec} \bifuncindex{eval} -\bifuncindex{execfile} \bifuncindex{compile} diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 74468b1..b39cd47 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -409,14 +409,14 @@ this file. If you want to read an additional start-up file from the current directory, you can program this in the global start-up file using code like \samp{if os.path.isfile('.pythonrc.py'): -execfile('.pythonrc.py')}. If you want to use the startup file in a +exec(open('.pythonrc.py')).read()}. If you want to use the startup file in a script, you must do this explicitly in the script: \begin{verbatim} import os filename = os.environ.get('PYTHONSTARTUP') if filename and os.path.isfile(filename): - execfile(filename) + exec(open(filename).read()) \end{verbatim} @@ -2736,14 +2736,14 @@ standard module \module{__builtin__}\refbimodindex{__builtin__}: '__name__', 'abs', 'basestring', 'bool', 'buffer', 'chr', 'classmethod', 'cmp', 'compile', 'complex', 'copyright', 'credits', 'delattr', 'dict', 'dir', 'divmod', - 'enumerate', 'eval', 'execfile', 'exit', 'file', 'filter', 'float', + 'enumerate', 'eval', 'exec', 'exit', 'filter', 'float', 'frozenset', 'getattr', 'globals', 'hasattr', 'hash', 'help', 'hex', 'id', 'input', 'int', 'isinstance', 'issubclass', 'iter', - 'len', 'license', 'list', 'locals', 'long', 'map', 'max', 'min', + 'len', 'license', 'list', 'locals', 'map', 'max', 'min', 'object', 'oct', 'open', 'ord', 'pow', 'property', 'quit', 'range', 'repr', 'reversed', 'round', 'set', 'setattr', 'slice', 'sorted', 'staticmethod', 'str', 'sum', 'super', - 'tuple', 'type', 'unichr', 'unicode', 'vars', 'zip'] + 'tuple', 'type', 'vars', 'zip'] \end{verbatim} @@ -4413,8 +4413,8 @@ the debugger, and that's one reason why this loophole is not closed. (Buglet: derivation of a class with the same name as the base class makes use of private variables of the base class possible.) -Notice that code passed to \code{exec()}, \code{eval()} or -\code{execfile()} does not consider the classname of the invoking +Notice that code passed to \code{exec()} or \code{eval()} +does not consider the classname of the invoking class to be the current class; this is similar to the effect of the \code{global} statement, the effect of which is likewise restricted to code that is byte-compiled together. The same restriction applies to |