@@ -942,7 +942,7 @@ There are various techniques.
942
942
f()
943
943
944
944
945
- * Use :func: `locals ` or :func: ` eval ` to resolve the function name::
945
+ * Use :func: `locals ` to resolve the function name::
946
946
947
947
def myFunc():
948
948
print("hello")
@@ -952,12 +952,6 @@ There are various techniques.
952
952
f = locals()[fname]
953
953
f()
954
954
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.
961
955
962
956
Is there an equivalent to Perl's chomp() for removing trailing newlines from strings?
963
957
-------------------------------------------------------------------------------------
@@ -1381,20 +1375,6 @@ out the element you want. ::
1381
1375
['else', 'sort', 'to', 'something']
1382
1376
1383
1377
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
-
1398
1378
Objects
1399
1379
=======
1400
1380
0 commit comments