Skip to main content

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

This version

0.1

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)

Uploaded Source

Built Distribution

ClassMaker-0.1-py3-none-any.whl (2.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page