2
class A(object):
    test = 'test'
    d = ['a', 'b']
    [i + test for i in d]

In python2.7, this code works, in python3.6, will report NameError: name 'test' is not defined.

I assume it's related to class attribute working scope change , but haven't found anythings in doc.

Haifeng Zhang
  • 27,283
  • 17
  • 68
  • 115
  • 1
    check out here https://stackoverflow.com/questions/13905741/accessing-class-variables-from-a-list-comprehension-in-the-class-definition – Haifeng Zhang Jun 05 '18 at 04:36

0 Answers0