Maximillian Wadkins Maximillian Wadkins - 1 month ago 4x
Python Question

__init__() compared to

I am working on a game right now but I really hate having a few thousand lines to scroll through when finding a bug to fix or a new feature has stuffed up another function. I have kept everything in one main class and when I looked into writing each function into a different file, I had one problem, I couldn't find anything

class game:
def __init__( self ): = "Foo"
def function( self, bar ): = bar

so if we put it into a file system, it should look something like this




and I do not know how to pass self or function into either init or funtion. Is there some sort of
__ = ( self, bar ) code that will help me, or will I continue to have to scroll through heaps of code?


I was wrong in my comment, you can do as you describe, but as @Ignacio stated its not good code design. Here's an example anyway because I was curious:

#Empty my_game 'class'
class my_game:

#Function you can put in a different file and import here
#Will become set as the new init function to 'my_game'
def my_games_init(self,x,y):
    self.x = x
    self.y = y

#Assigning 'my_games_init' function to be used as init of 'my_game' class
my_game.__init__ = my_games_init

#Make a 'my_game' instance and show that it's x and y methods were set
g = my_game(1,2)
print g.x
print g.y