Aug-22-2019, 04:07 PM
** 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:
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()