Am 26.11.2010 18:46, schrieb Gaëtan Podevijn:
I need to get some informations from files stored on my filesystem, Flickr
and Picasa. So the idea is to create a class (for instance,
"InformationsProvider") that provides common methods for those three
sources, then, for each source, I create a class that inherits from
"InformationsProvider" such as "InformationsLocalProvider",
"InformationsFlickrProvider" and "InformationPicasaProvider". It is clearly
needed because the method to get the informations is totally different for
each source (the connection with flickr or picasa for exemple).
However, I'd like, in the future, to be able to add new source and thus,
just add a new class that implements the methods from Provider. The thing
is, I'd like to add only one class, and that the rest of the application is
able to use that class without really knowing how many class there are.
I'd have something like :
for each provider that exists: get the informations file
and if I add a new .py that implements a new provider (say Delicious of
GMail), the code above takes account of the new class. It must be "dynamic".
Hello Gaëtan,
if all your classes are direct descendants of InformationsProvider
you might
get away with looping over InformationsProvider.__subclasses__().
See http://docs.python.org/library/stdtypes.html#class.__subclasses__
Greetings
Rainer
--
http://mail.python.org/mailman/listinfo/python-list