classification
Title: Fix FAQ example to use __import__('functools').reduce
Type: Stage: resolved
Components: Documentation Versions: Python 3.10, Python 3.9, Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: cryvate, docs@python, eric.smith, wyz23x2
Priority: normal Keywords:

Created on 2020-07-25 12:38 by wyz23x2, last changed 2020-07-25 13:29 by eric.smith. This issue is now closed.

Messages (3)
msg374258 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-07-25 12:38
https://docs.python.org/3/faq/programming.html#is-it-possible-to-write-obfuscated-one-liners-in-python
https://github.com/python/cpython/blob/3.8/Doc/faq/programming.rst
The 3rd raises a NameError because reduce was moved into functools. __import__('functools').reduce should fix this.
msg374259 - (view) Author: Henk-Jaap Wagenaar (cryvate) * Date: 2020-07-25 12:47
It doesn't raise an error when you run the whole example, it has "from functools import reduce" at the top.
msg374265 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-07-25 13:29
I agree that the example is okay as-is.

Plus, I can't see us using __import__ in examples. "import" is the preferred way to load modules.

Although now that I think about it, maybe __import__ would fit in with the subject "Is it possible to write obfuscated one-liners in Python?"!
History
Date User Action Args
2020-07-25 13:29:30eric.smithsetnosy: + eric.smith
messages: + msg374265
2020-07-25 12:49:19serhiy.storchakasetstatus: open -> closed
resolution: not a bug
stage: resolved
2020-07-25 12:47:43cryvatesetnosy: + cryvate
messages: + msg374259
2020-07-25 12:38:04wyz23x2create