我有這個類bgp_route:初學者蟒蛇錯誤 - 沒有屬性發現
class bgp_route:
def _init_(self, path):
self.nextHop = None
self.asPath = ''
self.asPathLength = 0
self.routePrefix = None
然而,當我運行下面的測試代碼;
from bgp_route import bgp_route
testRoute = bgp_route()
testRoute.asPath += 'blah'
print testRoute.asPath
我得到以下錯誤:
Traceback (most recent call last):
File "testbgpRoute.py", line 6, in <module>
testRoute.asPath += 'blah'
AttributeError: bgp_route instance has no attribute 'asPath'
什麼是這個錯誤的原因是什麼? bgp_route的實例不應該將屬性asPath初始化爲空字符串嗎?
你需要'__init__'不'_init_'。 –