The code I have is:
class New(Server):
noOfCl = 0
def onConnect(self, socket):
print "Client connected"
print (noOfCl+=1)
I am receiving the following error: UnboundLocalError: local variable 'noOfCl' referenced before assignment. From what I understand, I'm declaring noOfCl before I am referencing it. Anyone have any ideas as to what I'm doing wrong?
Thanks
asked Apr 29, 2012 at 19:50
AkshaiShah
5,97911 gold badges40 silver badges45 bronze badges
1 Answer 1
As noOfCl is a Class Variable you need to prefix the Class Name before it.
class New(Server):
noOfCl = 0
def onConnect(self, socket):
print "Client connected"
New.noOfCl+=1
print(New.noOfCl)
Also your in-place update when calling the print function/statement is not supported in Python.
answered Apr 29, 2012 at 19:54
Abhijit
64k20 gold badges143 silver badges209 bronze badges
lang-py
NameError.