Repository navigation
[doc] Error in functional how-to example #84152
Description
Activity
Hello,
A code example from the 'functional programming how-to' raises an error.
The simplest fix would be to remove the Ellipsis object from the 'line_list'.
Thank you,
DiogoPlease check below for the commands issued:
# https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions
>>> line_list = [' line 1\n', 'line 2 \n', ...] >>> >>> # Generator expression -- returns iterator >>> stripped_iter = (line.strip() for line in line_list) >>> >>> # List comprehension -- returns list >>> stripped_list = [line.strip() for line in line_list] Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 1, in <listcomp> AttributeError: 'ellipsis' object has no attribute 'strip'
- addeddocsDocumentation in the Doc dirDocumentation in the Doc dir3.8 (EOL)end of lifeend of life
on Mar 15, 2020 I don't think that was meant to be a literal example. I think that "..." here means "and other strings".
Agreed, Eric. Nevertheless, I think that this example might raise unnecessary confusion to someone new to Python, and hence the reason why I decided to open the issue. Anyhow, I trust your judgement and please feel free to leave things as is and close this issue.
PS: I really the work you did with dataclasses, and I actually explored the idea further with a small (300 LoC) library that adds runtime type checking for instances of dataclasses - if you are ever curious you can find the code on my GitHub at /dxflores/invis.
Thank you,
DiogoIn think examples should run and that '...' should be replaced by something like "' \n', ''". The blank string looks ahead to the next example, which adds ' if line != ""' to the comprehension.
- changed the title
[-]Error on documentation - Quick fix.[/-][+]Error in functional how-to example[/+]on Mar 20, 2020 2 remaining items
Looking around further, examples meant to be executable as is are given interactive prompts and needed doctest directives
>>> gen #doctest: +ELLIPSIS <generator object generate_ints at ...>I think that this example should get the same treatment. Non-executable examples are usually clearly non-executable because then contain undefined names line 'expr2' and 'sequence2', whereas this example starts by defining 'line_list'.
- added3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesand removed3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life
on Mar 20, 2022 - changed the title
[-]Error in functional how-to example[/-][+][doc] Error in functional how-to example[/+]on Mar 20, 2022 - added3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixesand removed3.7 (EOL)end of lifeend of life3.8 (EOL)end of lifeend of life
on Mar 20, 2022 - changed the title
[-]Error in functional how-to example[/-][+][doc] Error in functional how-to example[/+]on Mar 20, 2022
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: