SRL Archive - Python/Perl Help and Tutorials

Add functions to a class at runtime(python)


KingKong

2012-01-10 22:37:03

This is my folder structure:
PySRL/
pymml/
__init__.py
libsmart.dll
mtypes.py
SMART.py

Includes/
__init__.py

core/
__init__.py
gametab.py
login.py


SMART.py contains one class named Smart. I wish to add all the functions within gametab.py and login.py(more files to come later on) to the class Smart at runtime. Whats the best to do this dynamically?(As in i run another python file which iterates through all the modules inside core)

Dan Cardin

2012-01-11 08:54:56

class Smart()
__init__(self, Anyclass, anyclass2):
self.gametab = Anyclass
self.login = anyclass2

meow = Class(gametab, login)
like that? or am i misunderstanding

KingKong

2012-01-11 18:02:54

see how you wrote self.gametab? I want it to loop through all the files in includes and then add all the functions in all those files to class Smart at runtime, instead of hardcoding them.

Dan Cardin

2012-01-12 08:56:54

oh i thought you just wanted to import a single class's functions. I'm not sure you could do it without at least already having the names of all of the classes hardcoded somewhere in here.

slacky

2013-02-27 15:10:21

Edit: And then i noted that the thread is a hundred years old.