For some reason I'm getting a global name is not defined
error here. The issue lies in the addClient
method where I am incrementing my global variable joinID
. It throws me an error NameError: global name 'joinID' is not defined
. What am I doing wrong?
class Chatroom:
clients = []
joinID = 0
def __init__(self,name,refNum):
self.refNum = refNum
self.name = name
def addClient(self,clientName):
global clients
global joinID
joinID = joinID+1
clients.append(clientName, joinID)
def removeClient(self, clientName, joinID):
global clients
clients.remove(clientName, joinID)
In a method from a class is bether to use a instance attribute or a class atribute. In this case you are using a class atribute.
If you wan´t to use global, you must declare the variable in the global scope:
Take the variables outside the class