<p>我试图初始化一个实例,但每次都会抛出一个错误:</p>
<pre><code>import random
class cGen:
attributes = ['a','b','c']
def __init__(self):
self.att = random.choice(attributes)
</code></pre>
<p>我可以很好地导入该类,但出现错误:</p>
<pre class="lang-none prettyprint-override"><code>>>> c1 = cGen()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File ".\xGen.py", line 288, in __init__
self.att = random.choice(attributes)
NameError: name 'attributes' is not defined
</code></pre>
<p>我错过了什么</p>