The issue here is that you are using a local variable when you should be using an instance variable.
Calling a function or method creates a new namespace, which exists only for the duration of the call. In order for the value of workerNo
(worker_no
would be better according to PEP 8, the standard for Python code) to persist beyond the __init__()
method call it has to be stored in a namespace that doesn't evaporate.
Each instance has such a namespace (which is created when its class is instantiated), and the self
(first) argument to every method call gives access to that namespace. So in your __init__()
method you should write
self.workerNo = wId
and then you can access it from the other methods (since they also receive a self
argument referring to the same namespace. External references to the instance can also access the instance attributes.