Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78b1187

Browse files
committed
Fix now-wrong :keyword: markup. Remove the section about
"exec without namespace" from the "don't" howto since exec() can't overwrite names in the calling namespace anymore.
1 parent c31b0f7 commit 78b1187

3 files changed

Lines changed: 2 additions & 35 deletions

File tree

Doc/howto/doanddont.rst

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,39 +75,6 @@ There are situations in which ``from module import *`` is just fine:
7575
* When the module advertises itself as ``from import *`` safe.
7676

7777

78-
Unadorned :keyword:`exec` and friends
79-
-------------------------------------
80-
81-
The word "unadorned" refers to the use without an explicit dictionary, in which
82-
case those constructs evaluate code in the *current* environment. This is
83-
dangerous for the same reasons ``from import *`` is dangerous --- it might step
84-
over variables you are counting on and mess up things for the rest of your code.
85-
Simply do not do that.
86-
87-
Bad examples::
88-
89-
>>> for name in sys.argv[1:]:
90-
>>> exec "%s=1" % name
91-
>>> def func(s, **kw):
92-
>>> for var, val in kw.items():
93-
>>> exec "s.%s=val" % var # invalid!
94-
>>> exec(open("handler.py").read())
95-
>>> handle()
96-
97-
Good examples::
98-
99-
>>> d = {}
100-
>>> for name in sys.argv[1:]:
101-
>>> d[name] = 1
102-
>>> def func(s, **kw):
103-
>>> for var, val in kw.items():
104-
>>> setattr(s, var, val)
105-
>>> d={}
106-
>>> exec(open("handle.py").read(), d, d)
107-
>>> handle = d['handle']
108-
>>> handle()
109-
110-
11178
from module import name1, name2
11279
-------------------------------
11380

Doc/library/bdb.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ The following two methods can be called by clients to use a debugger to debug a
294294

295295
.. method:: Bdb.run(cmd, [globals, [locals]])
296296

297-
Debug a statement executed via the :keyword:`exec` statement. *globals*
297+
Debug a statement executed via the :func:`exec` function. *globals*
298298
defaults to :attr:`__main__.__dict__`, *locals* defaults to *globals*.
299299

300300
.. method:: Bdb.runeval(expr, [globals, [locals]])

Doc/tutorial/controlflow.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ like in C, procedures are just functions that don't return a value. In fact,
263263
technically speaking, procedures do return a value, albeit a rather boring one.
264264
This value is called ``None`` (it's a built-in name). Writing the value
265265
``None`` is normally suppressed by the interpreter if it would be the only value
266-
written. You can see it if you really want to using :keyword:`print`::
266+
written. You can see it if you really want to using :func:`print`::
267267

268268
>>> fib(0)
269269
>>> print(fib(0))

0 commit comments

Comments
 (0)