之前變量引用我的代碼是:Python的 - 分配
class New(Server):
noOfCl = 0
def onConnect(self, socket):
print "Client connected"
print (noOfCl+=1)
我收到以下錯誤:UnboundLocalError: local variable 'noOfCl' referenced before assignment.
據我瞭解,我聲明瞭noOfCl之前我引用它。任何人有什麼想法,我做錯了什麼? 謝謝
此代碼不會拋出您描述的錯誤。它拋出一個簡單的'NameError'。 – senderle