【发布时间】:2015-03-25 02:31:45
【问题描述】:
我是 python 新手,这是我在 python 中的第一个程序,我想知道如何访问类外部的类变量。我有一个会引发一些错误的代码
from xxxxxxx import Products
class AccessKey(object):
def key(self):
self.products = Products(
api_key = "xxxxxxxxxxxxxxxxxxxxxx",
api_secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
)
class Data(AccessKey):
def Print(self):
products.products_field( "search", "Samsung Galaxy" )
results = products.get_products()
print "Results of query:\n", results
data = Data()
data.Print()
上面的程序抛出以下错误
Traceback (most recent call last):
File "framework.py", line 10, in <module>
class Data(AccessKey):
File "framework.py", line 13, in Data
results = products.get_products()
NameError: name 'products' is not defined
【问题讨论】:
标签: python class variables scope