A python module to help with meta classes
Project description
A helper class to programaticly build a Meta Class
Install
git clone https://gitlab.com/craigukaea/class-maker.git
cd class-builder
./Install
Use
To build a class equivelent to the following:
class Foo:
def bar():
print("Hello world")
Use:
maker = ClassMaker()
maker.setClassName('Foo')
maker.addFunction('bar', lambda : print("Hello World!"))
#make the class
foo = maker.makeClass()
##test the functions
foo.__init__()
foo.bar()
Example
from ClassMaker import ClassMaker
if __name__ == "__main__":
maker = ClassMaker()
maker.setClassName('Foo')
maker.addFunction('bar', lambda : print("Hello World!"))
maker.addVariable('baz', 5)
maker.addFunctionToInitialiser(lambda : print("Initialising"))
maker.addFunctionToInitialiser(lambda : print("!"))
foo = maker.makeClass()
foo.__init__()
foo.bar()
print(foo.baz)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ClassMaker-0.1.tar.gz
(2.1 kB
view hashes)