Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling another member function from __init__ in python [duplicate]

Tags:

python

I wanted to call class member functions to initialize the class members completely in init. items_left and rat_initialize are the member functions I am using to initialize all the members of the class instance correctly. Is it alright to do so?

class Maze:
    """ A 2D maze. """
    # Write your Maze methods here.
    def __init__(self,maze,rat_1,rat_2):
        self.maze = maze
        self.rat_1 = rat_1
        self.rat_2 = rat_2
        self.num_sprouts_left = 0
        self.items_left(maze)
        self.rat_initialize(maze,rat_1,rat_2)
like image 508
vkaul11 Avatar asked Dec 11 '22 15:12

vkaul11


1 Answers

Yes you can do it. When __init__ is called, the object is already instantiated by this point all the methods are available.

Actual object instantitation takes place in __new__ and __init__ is only called after it. You have accesss to other functions from inside __init__.

like image 162
Akshar Raaj Avatar answered Apr 28 '23 15:04

Akshar Raaj