I am not a complete beginner but fairly new to Python. Whilst working on a project today I just had an idea and wondered regarding the usage of "self"; about which I've been reading for the past some while and I still can not figure out if it's always necessary or not. My question solely concerns instances of classes and instance parameters/variables. This question is not about Class Variables which affect all instances.
Example:
class C:
def __init__(self, parent = None):
super(C, self).__init__(parent)
self.some_temp_var = AnotherClass()
self.important_property = self.some_temp_var.bring_the_jewels()
ins_c = C()
print ins_c.important_property
In the above code, I use self before both variable declarations (some_temp_var and important_property).
I will need to access **important_property** later from the outside (where instance's been created) and maybe even modify it.
But I will not need access to the instance of AnotherClass() and/or variable pointing to it (some_temp_var). I just need an instance of it class once, and I need to execute its method bring_the_jewels only once to populate value of important_property.
Should I still use self before declaring that variable as well?
self.some_temp_var = ....
self.important_property = ....
or can it be:
some_temp_var = ....
self.important_property = ....
Thank you for your help.
Ps. I did my research in a length way. Due to lack of my English and/or CS knowledge, I may not have found a currently existing duplicate however I did search and I did search a lot. Before calling this question "duplicate" or "not constructive" please read it throughly. This is a question with clear answer and it's very important, and complicated matter. Thank you for your understanding.