所以我整天都在乱搞这个问题,但我仍然无法让它发挥作用
class pleaseWork:
def __init__(self):
self.foo=printThis(1)
self.bar=printThis(2)
def printThis(x):
if x==1:
print "foot"
elif x==2:
print "bar"
result=pleaseWork()
result.bar
Run Code Online (Sandbox Code Playgroud)
它只是回来了
NameError: global name 'printThis' is not defined
Run Code Online (Sandbox Code Playgroud)
请告诉我为什么它不起作用......
因为printThis是当前对象的属性.
self.foo = self.printThis(1)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3138 次 |
| 最近记录: |