How to organize a Python module with lots of constants and exceptions? -
i'm writing python module has twenty interesting types , global methods, lots of constants , exceptions (about 70 constants locales, 60 constants encodings, 20 formatting attributes, more 200 exceptions, , on). result help() on module produces 16,000 lines of text , littered identical descriptions of each exception. constants not demanding, it's still difficult navigate them.
what pythonic way organize such module? leave , rely on other documentation? move constants separate dicts? submodules? add them class-level constants, appropriate?
note c extension cannot add real submodule here. i've heard sys.modules doesn't check if object there module, 1 add dictionaries there; way create mymodule.locales, mymodule.encoding, , mymodule.exceptions , add them sys.modules when module imported. idea or it's hackish?
there 2 options solve problem. first approach classify constants , exceptions, , have smaller number of broader categories. allow navigate categories want. dictionary (or nested dictionaries) way implement this, maintain groups titles in them. second way if wanted customize management little bit more make class act bit dictionary. have list of children objects. way, make unique, easier access methods navigate through of constants , exceptions, such new exception class handles several similar exceptions. other way make cleaner, require access source, make of exceptions smaller group of exceptions can each handle groups of similar problems. better way deal exceptions, may not have access source modify this.
Comments
Post a Comment