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
  • 30,077
  • 19
  • 81
  • 125
monsterxx03
  • 96
  • 1
  • 7
  • 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