2

I've noticed that every once in a while, someone will write a class in python along these lines

class Example(object):
    def __init__(self):
        self.x = 5

    def some_method(self):
        # Do stuff to self.x

    def get_results(self):
        return self.x

My question is concerning the get_results method, which seems superfluous to me since self.x can be accessed directly with instance_name.x. Is there a reason why including a method like this would be necessary/preferable? Is it an artifact of a programmer's experience with other languages?

philE
  • 1,655
  • 15
  • 20
  • 2
    This is an opinion, so I'm not putting it as an answer, but, yes, I think this is due to experience with other languages like Java. As the saying goes, you can write FORTRAN in any language. – TigerhawkT3 Jun 19 '15 at 17:50
  • 1
    You asked a slightly different question, but the answer to your question, and other strongly related discussion is covered in great detail in the above link. – Cory Kramer Jun 19 '15 at 17:52

0 Answers0