As I was reading this tutorial about tkinter
for my first steps with GUI in Python, I realized that a class function was called inside the __init__
function.
I'd to like to understand, for what reason must be declared self.class_function()
when calling a class function inside __init__
function?
I found this question with this answer below, which just says that it must be called self.class_function
and not class_function
, without providing any concept or explanation about why it must be done like this:
class MyClass():
def __init__(self, filename):
self.filename = filename
self.stat1 = None
self.stat2 = None
self.stat3 = None
self.stat4 = None
self.stat5 = None
self.parse_file()
def parse_file(self):
#do some parsing
self.stat1 = result_from_parse1
self.stat2 = result_from_parse2
self.stat3 = result_from_parse3
self.stat4 = result_from_parse4
self.stat5 = result_from_parse5