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 2016年12月19日 03:17 by Assume_Away, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (3) | |||
|---|---|---|---|
| msg283575 - (view) | Author: Dan Snider (Assume_Away) * | Date: 2016年12月19日 03:17 | |
class MyClass:
a_dict = {'key':'value'}
r_dict = {a_dict[k]:k for k in a_dict}
throws the error:
Traceback (most recent call last):
File "C:/Users/D/AppData/Local/Programs/Python/Python35-32/deleteme.py", line 1, in <module>
class MyClass:
File "C:/Users/D/AppData/Local/Programs/Python/Python35-32/deleteme.py", line 3, in MyClass
r_dict = {a_dict[k]:k for k in a_dict}
File "C:/Users/D/AppData/Local/Programs/Python/Python35-32/deleteme.py", line 3, in <dictcomp>
r_dict = {a_dict[k]:k for k in a_dict}
NameError: name 'a_dict' is not defined
|
|||
| msg283576 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年12月19日 03:39 | |
This is by design in 3.x. You can refer #11796 for explanation. |
|||
| msg283577 - (view) | Author: Xiang Zhang (xiang.zhang) * (Python committer) | Date: 2016年12月19日 04:10 | |
Also http://stackoverflow.com/a/4199355/2189957. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:40 | admin | set | github: 73194 |
| 2016年12月19日 04:30:27 | terry.reedy | set | assignee: terry.reedy -> nosy: - terry.reedy |
| 2016年12月19日 04:10:12 | xiang.zhang | set | messages: + msg283577 |
| 2016年12月19日 03:39:53 | xiang.zhang | set | status: open -> closed superseder: Comprehensions in a class definition mostly cannot access class variable nosy: + xiang.zhang messages: + msg283576 resolution: not a bug stage: resolved |
| 2016年12月19日 03:17:19 | Assume_Away | create | |