sys.path butchery - Printable Version +- Kodi Community Forum (https://forum.kodi.tv) +-- Forum: Development (https://forum.kodi.tv/forumdisplay.php?fid=32) +--- Forum: Add-ons (https://forum.kodi.tv/forumdisplay.php?fid=26) +--- Thread: sys.path butchery (/showthread.php?tid=180711) |
sys.path butchery - powlo - 2013-12-18 I see a lot of this kind of thing: Code: import xbmcaddon 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. RE: sys.path butchery - Martijn - 2013-12-18 No RE: sys.path butchery - powlo - 2013-12-18 thnks RE: sys.path butchery - Martijn - 2013-12-18 Best is: from resources.lib import foo All the rest is hackery and should not be used RE: sys.path butchery - sphere - 2013-12-20 (2013-12-18, 22:48)Martijn Wrote: Best is: 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). RE: sys.path butchery - powlo - 2013-12-20 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. RE: sys.path butchery - Bstrdsmkr - 2013-12-22 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.video.waldo/blob/master/utils.py RE: sys.path butchery - amet - 2013-12-22 it just carried from years back, I agree that "from resources.lib import foo" is best |