import - best way to register all classes in a folder in python -
i working summer intern @ large company, me , intern has been tasked writing background service scratch in python(with given specifications). can't python expert try write code possible , follow practice. describe service in easy way receives messages buss (amqp atm) , matches them against patterns , preform actions depending on pattern, configurable json file.
to down point, service suppose general , therefore developer should able add different inputs , outputs classes. structure have right now.
- service.py
- input
- __init__.py (includes .py files in __all__ variable)
- base.py
- amqp.py
service.py
from input import * import input #use input.base.sources
input\base.py
sources = {} def register_input(cls): sources[cls.input_name] = cls return cls class inputbase(object): action(self, params): ...
input\amqp.py
@register_input class amqpinterface(inputbase): input_name = "amqp" action(self, params): ...
this works, doesn't nice , creates problems include orders. neither nor senior developer think of more pythonic way of solving this. have ideas how solve problem in more elegant way?
Comments
Post a Comment