sys.path butchery
#1
I see a lot of this kind of thing:

Code:
import xbmcaddon

__addon__       = xbmcaddon.Addon()
__addonpath__   = __addon__.getAddonInfo('path')
__resource__    = os.path.join( __addonpath__, 'resources', 'lib' )
sys.path.append(__resource__)

Is there any way to avoid this kind of butchery? (other than "from resources.lib import ...") Is there something that can be added to addon.xml that defines a folder to be added to sys.path? I can't find anything but thought I'd ask.
Reply
#2
No
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
thnks
Reply
#4
Best is:
from resources.lib import foo

All the rest is hackery and should not be used
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#5
(2013-12-18, 22:48)Martijn Wrote: Best is:
from resources.lib import foo

All the rest is hackery and should not be used

Correct. But to be able to do that you need a file "__init__.py" in "resources" and one in "lib". These files may be empy but are required for folder/module imports (package imports).
My GitHub. My Add-ons:
Image
Reply
#6
Yes yes. I'm a little uncomfortable mixing up python packages and other file types but I guess its the best solution. Alternatively don't put packages under resources/lib/? I can't really understand why this is stipulated to be honest.
Reply
#7
You could use imp.load_module() which is more or less what import does on the back end, but I'm not all together sure that's better. Example: https://github.com/bstrdsmkr/plugin.vide...r/utils.py
Reply
#8
it just carried from years back, I agree that "from resources.lib import foo" is best
Reply

Logout Mark Read Team Forum Stats Members Help
sys.path butchery0