You are trying to assign a message_count global variable without declaring it as such:
message_count = 0 class sms_store: def add_new_arrival(self,number,time,text): store.append(("From: "+number, "Recieved: "+time,"Msg: "+text)) global message_count message_count += 1
Try to avoid using globals or at least encapsulate a variable as an attribute of a class:
class sms_store: message_count = 0 store = [] def add_new_arrival(self,number,time,text): sms_store.append(("From: "+number, "Recieved: "+time,"Msg: "+text)) sms_store.message_count += 1
However, your class instances no longer have a state, so it makes no sense to create a class. This only confuses your goal.
either save state in instances, or use global functions (so don't use the class at all); the former is preferable to the latter.
Converting your installation to a class whose instances are state-safe using the correct PEP-8 style notation and line formatting:
class SMSStore(object): def __init__(self): self.store = [] self.message_count = 0 def add_new_arrival(self, number, time, text): self.store.append('From: {}, Received: {}, Msg: {}'.format(number, time, text)) self.message_count += 1
Then you can create one instance and use it as a global one if necessary:
sms_store = SMSStore()
Another code just uses sms_store.add_new_arrival(...) , but the state is encapsulated in one instance.