1. b.93z.org
  2. Notes

Methods of class and __init__ in Python

Some people still don’t know that following will work.

class SomeClass(object):

    def __init__(self, some_string):
        self.final_string = self.second_method(self.first_method(some_string))

    def first_method(self, string):
        return string

    def second_method(self, string):
        return string

If you’ll execute following (in addition), you’ll see it works (self.final_string contains a string):

>>> test = SomeClass('Hello, World')
>>> print test.final_string
Hello, World

© 2008–2017 93z.org