I have a plugin system. The plugins subclass from a common ancestor... ad look like this:
-- SDK
--- basePlugin.py
-- PLUGINS
--- PluginA
---- Plugin.py
---- Config.ini
--- PluginB
---- Plugin.py
---- Config.ini
I need to read the info of Config.ini
in basePlugin.py __init__
. CUrrently in each plugin I do:
class PluginA(BaseSync):
__init__(self, path):
super(PluginA,self).__init__(self, __file__)
But wonder if is possible to know in the parent class in which file is located the sub-class...
Assuming BaseSync
is a new-style class, the parent class BaseSync
could find the file that defines PluginA
this way:
import sys
class BaseSync(object):
def __init__(self):
path=sys.modules[self.__module__].__file__
(so you don't have to pass the path
explicitly).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With