I'm writing a Python module that has only about twenty interesting types and global methods, but lots of constants and exceptions (about 70 constants for locales, 60 constants for encodings, 20 formatting attributes, more than 200 exceptions, and so on). As a result help() on this module produces about 16,000 lines of text and is littered with nearly identical descriptions of each exception. The constants are not that demanding, but it's still difficult to navigate them.
What would be a pythonic way to organize such a module? Just leave it as is and rely on other documentation? Move constants into separate dicts? Into submodules? Add them as class-level constants, where appropriate?
Note that this is a C extension so I cannot easily add a real submodule here. I've heard that sys.modules doesn't really check if the object there is a module, so one could add dictionaries there; this way I could probably create mymodule.locales, mymodule.encoding, and mymodule.exceptions and add them into sys.modules when my module is imported. Would this be a good idea or it's too hackish?
There are really two options to solve your problem. The first approach is to classify all the constants and exceptions, and have a smaller number of broader categories. This would allow you to easily navigate into which categories you want. A dictionary (or probably nested dictionaries) would be a good way to implement this, as you could maintain groups with titles in them. A second way you could do this if you wanted to customize the management a little bit more would be to make a class that would act a bit like a dictionary. It would have a list of children objects. This way, you could make unique, easier to access methods to navigate through all of your constants and exceptions, such as a new exception class that handles several similar exceptions. The other way to make it cleaner, which would require access to the source, would be to make all of those exceptions into a smaller group of exceptions that can each handle groups of similar problems. This would probably be a better way to deal with the exceptions, but you may not have access to the source to modify this.
How to organize a Python module with lots of constants and exceptions?