Skip to content

Commit a22a19f

Browse files
authored
bpo-40341: Remove some "discouraged solutions" in Doc/faq/programming.rst (GH-22726)
1 parent 1dd6d95 commit a22a19f

File tree

1 file changed

+1
-21
lines changed

1 file changed

+1
-21
lines changed

Doc/faq/programming.rst

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,7 @@ There are various techniques.
942942
f()
943943

944944

945-
* Use :func:`locals` or :func:`eval` to resolve the function name::
945+
* Use :func:`locals` to resolve the function name::
946946

947947
def myFunc():
948948
print("hello")
@@ -952,12 +952,6 @@ There are various techniques.
952952
f = locals()[fname]
953953
f()
954954

955-
f = eval(fname)
956-
f()
957-
958-
Note: Using :func:`eval` is slow and dangerous. If you don't have absolute
959-
control over the contents of the string, someone could pass a string that
960-
resulted in an arbitrary function being executed.
961955

962956
Is there an equivalent to Perl's chomp() for removing trailing newlines from strings?
963957
-------------------------------------------------------------------------------------
@@ -1381,20 +1375,6 @@ out the element you want. ::
13811375
['else', 'sort', 'to', 'something']
13821376

13831377

1384-
An alternative for the last step is::
1385-
1386-
>>> result = []
1387-
>>> for p in pairs: result.append(p[1])
1388-
1389-
If you find this more legible, you might prefer to use this instead of the final
1390-
list comprehension. However, it is almost twice as slow for long lists. Why?
1391-
First, the ``append()`` operation has to reallocate memory, and while it uses
1392-
some tricks to avoid doing that each time, it still has to do it occasionally,
1393-
and that costs quite a bit. Second, the expression "result.append" requires an
1394-
extra attribute lookup, and third, there's a speed reduction from having to make
1395-
all those function calls.
1396-
1397-
13981378
Objects
13991379
=======
14001380

0 commit comments

Comments
 (0)