View Full Version : executing a def from a py file being executed by that file...

05-18-2011, 04:53 AM
not sure how i would search something like that up...

Theres this game that im looking at that ive modded a bit, and so theres a core file that import the addon file in that addon file there is the __init__(self, core) making it possible to execute defs inside the core so they do something like this
class core:
def printHello():
print "Hello Moto"

def importme():

class Addon:
def __init__(self, core):
self.core = core

def saysomething():

and if you executed saysomething it would run printHello

im not sure how they were able to pass the class over to that class as if you were importing it...

i hope this is clear enough, please help.

07-08-2011, 06:04 PM
It would make sense if core.py looked like:

class core:

def printHello(self):
print "Hello Moto"

and the script with AddOn (addon.py) looked like:

class AddOn:

def __init__(self, core):
self.core = core

def saySomething(self):

All you have to do is:

from core import core
from addon import AddOn

# Instantiate AddOn, passing to it an instance of core.
addon_instance = AddOn(core())

# Call saySomething.

That should say "Hello Moto".