This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2019年02月21日 23:25 by woodscn, last changed 2022年04月11日 14:59 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg336270 - (view) | Author: Nathan Woods (woodscn) | Date: 2019年02月21日 23:25 | |
The following code works in an interactive shell or in a batch file, but not when executed as part of a unittest suite or pdb: from random import random out = [random() for ind in range(3)] It can be made to work using pdb interact, but this doesn't help with unittest. Tested in Python 3.7.2 |
|||
| msg336271 - (view) | Author: Zachary Ware (zach.ware) * (Python committer) | Date: 2019年02月21日 23:35 | |
Can you attach a test file that shows the failure? |
|||
| msg336277 - (view) | Author: Eric V. Smith (eric.smith) * (Python committer) | Date: 2019年02月22日 03:04 | |
I suspect Nathan is seeing this problem at class scope. This is a well known issue: >>> class C: ... from random import random ... out = [random() for ind in range(3)] ... Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<stdin>", line 3, in C File "<stdin>", line 3, in <listcomp> NameError: name 'random' is not defined >>> It is not related to the list comprehension, but to the class scope. See the last paragraph of https://docs.python.org/3/reference/executionmodel.html#resolution-of-names But I agree with Zach about needing an example that fails. |
|||
| msg336278 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) | Date: 2019年02月22日 05:02 | |
This is a duplicate of issue3692. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:11 | admin | set | github: 80251 |
| 2019年02月22日 05:02:18 | serhiy.storchaka | set | status: open -> closed superseder: improper scope in list comprehension, when used in class declaration nosy: + serhiy.storchaka messages: + msg336278 resolution: duplicate stage: resolved |
| 2019年02月22日 03:04:54 | eric.smith | set | nosy:
+ eric.smith messages: + msg336277 |
| 2019年02月21日 23:35:15 | zach.ware | set | nosy:
+ zach.ware messages: + msg336271 |
| 2019年02月21日 23:25:38 | woodscn | create | |