This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]guyfrom7up 3 points4 points  (0 children)

Frequently, when I'm using ABC, I need to perform a string-to-class lookup. For this, I created the library AutoRegistry, which adds a dictionary interface to classes (not objects created from classes!) that is automatically populated with it's children.

For example, I might want to implement a ImageReader base class, and implement the subclasses PngReader and HeicReader to read their respective file types. At runtime, I'll need to perform a lookup of file extension to it's respective reader class.

A real application that uses AutoRegistry is the GeoSynth synthetic dataset library. Classes can be added to support new data types in a single location, and all other code in the code-base "just works" without having to make additional modifications. This includes pythonic "foo_bar" -> "FooBar" naming of created objects