Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
05-18-2011, 03:53 AM #1
- Join Date
- Mar 2009
- Thanked 0 Times in 0 Posts
executing a def from a py file being executed by that file...
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
print "Hello Moto"
def __init__(self, core):
self.core = core
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.The Game
07-08-2011, 05:04 PM #2
It would make sense if core.py looked like:
and the script with AddOn (addon.py) looked like:Code:class core: def printHello(self): print "Hello Moto"
All you have to do is:Code:class AddOn: def __init__(self, core): self.core = core def saySomething(self): self.core.printHello()
That should say "Hello Moto".Code:from core import core from addon import AddOn # Instantiate AddOn, passing to it an instance of core. addon_instance = AddOn(core()) # Call saySomething. addon_instance.saySomething()
I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
** Independent Multimedia Artist in Pasig **