Python으로 객체 지향 프로그래밍을 이해하려고합니다. 프로그래밍에 익숙하지 않습니다. 내가 이해하지 못하는 나에게 오류를주고있다이 클래스를 가지고 누군가가 나를 위해이에 더 많은 빛을 던질 수 있다면 나는 기꺼이됩니다Python 객체 지향 프로그래밍
class TimeIt(object):
def __init__(self, name):
self.name = name
def test_one(self):
print 'executed'
def test_two(self, word):
self.word = word
i = getattr(self, 'test_one')
for i in xrange(12):
sleep(1)
print 'hello, %s and %s:' % (self.word, self.name),
i()
j = TimeIt('john')
j.test_two('mike')
을 나는이 클래스를 실행하면 내가 'int' object is not callable" TypeError
그러나 내가 (self.i
)으로 i
앞에 오는 경우 작동합니다.
class TimeIt(object):
def __init__(self, name):
self.name = name
def test_one(self):
print 'executed'
def test_two(self, word):
self.word = word
self.i = getattr(self, 'test_one')
for i in xrange(12):
sleep(1)
print 'hello, %s and %s:' % (self.word, self.name),
self.i()
내 질문 i = getattr(self, 'test_one')
가 i
에 test_one 기능을 할당하지 않습니다입니까?
어떻게 i()
이 작동하지 않습니까?
self.i()
은 왜 작동합니까?
i
이 int
인 이유는 무엇입니까 ('int' object is not callable TypeError
)?
많은 질문이 있습니다. 미리 감사드립니다.
와
를 교체하는 방법을 호출 할 수 있습니다. xrange()를 반복하는 데 사용하기 때문에 'i'를 사용해서는 안됩니다. pheeew – kassold