You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>>> 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'
I don't think that was meant to be a literal example. I think that "..." here means "and other strings".
dxflores commented on Mar 16, 2020
dxfloresmannequin
MannequinAuthor
More actions
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.
In 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.
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'.
Activity
dxflores commentedon Mar 15, 2020
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,
Diogo
Please check below for the commands issued:
# https://docs.python.org/3/howto/functional.html#generator-expressions-and-list-comprehensions
ericvsmith commentedon Mar 16, 2020
I don't think that was meant to be a literal example. I think that "..." here means "and other strings".
dxflores commentedon Mar 16, 2020
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,
Diogo
terryjreedy commentedon Mar 20, 2020
In 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.
[-]Error on documentation - Quick fix.[/-][+]Error in functional how-to example[/+]2 remaining items
terryjreedy commentedon Mar 20, 2020
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'.
[-]Error in functional how-to example[/-][+][doc] Error in functional how-to example[/+][-]Error in functional how-to example[/-][+][doc] Error in functional how-to example[/+]