-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[doc] Error in functional how-to example #84152
Comments
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, Please 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' |
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, |
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. |
Working on PR. The example 1 further on has a stray meaningless ellipsis.
Perhaps this was meant to follow the next line, but I will remove it. |
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'. |
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:
The text was updated successfully, but these errors were encountered: