Python Forum
Why is there no __init_class__ method
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why is there no __init_class__ method
#2
** Please Note **
python-forum.io is not python.org, and is not the author of python

define all of the variables you need to use in other methods using self.name
they will then be visible to methods in the class, and also visible outside of the class if prefixed by the class name
There is no need for another __init__ unless using inheritance

example:
class alpha1:
    def __init__(self):
        self.prog_name = f"Program name: {__file__}"
    
    def show_name(self):
        print(f"\nIn show_name: {self.prog_name}\n")

class beta1:
    def __init__(self):
        a = alpha1()
        # print variable direct
        print(f"\nalpha1.prog_name: {a.prog_name}\n")
        # or by calling method of class
        print('\nBy calling method show_name:')
        a.show_name()

if __name__ == '__main__':
    beta1()
Reply


Messages In This Thread
Why is there no __init_class__ method - by Drecker - Aug-22-2019, 11:37 AM
RE: Why is there no __init_class__ method - by Larz60+ - Aug-22-2019, 04:07 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020