Last Updated: February 25, 2016
· maandree

Simple extensible Python code

Python supports dynamically loading python files and executing them.
A simple example on how to do this is:

code = None
with open(addon, 'r') as file:
    code = file.read() + '\n'
code = compile(code, addon, 'exec')
exec(code, globals())

And Python also supports defining methods:

class Class:
     def something(self):

def new_something(self):

Class.something = new_something.

But you can also union functions by storing them in a variable before replacing them and calling those variables inside the replacement functions.

This makes it simple to create extensible Python programs by just having executing an rc file that can load the addons and just replace and union functions. And to make the code more extensible, just keep in mind to have small functions.