Results 1 to 5 of 5

Thread: Add functions to a class at runtime(python)

  1. #1
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default Add functions to a class at runtime(python)

    This is my folder structure:
    Code:
    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)

  2. #2
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Code:
    class Smart()
        __init__(self, Anyclass, anyclass2):
            self.gametab = Anyclass
            self.login = anyclass2
    
    meow = Class(gametab, login)
    like that? or am i misunderstanding
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  3. #3
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    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.

  4. #4
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    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.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  5. #5
    Join Date
    Feb 2012
    Location
    Norway
    Posts
    995
    Mentioned
    145 Post(s)
    Quoted
    596 Post(s)

    Default

    Edit: And then i noted that the thread is a hundred years old.
    Last edited by slacky; 02-27-2013 at 09:17 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •