Kodi Community Forum
Tips for coding python scripts / plugins compatible with Linux, Mac, Windows AND Xbox - 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: Tips for coding python scripts / plugins compatible with Linux, Mac, Windows AND Xbox (/showthread.php?tid=36900)

Pages: 1 2


- BigBellyBilly - 2009-02-17

using os.getcwd() in conjunction with the recommended url style path divider '/' creates a path with mixed dividers.

ie.

DIR_HOME = os.getcwd().replace( ";", "" )
DIR_RESOURCES_LIB = "/".join( [DIR_HOME, "resources", "lib"] )
sys.path.insert(0, xbmc.translatePath(DIR_RESOURCES_LIB) )

gives

C:\Program Files\XBMC\scripts\<scriptname>/resources/lib

which is ugly, but it still works on win32 and xbox (don't know about others)
HOME_DIR is only really used as a base for relative subdirs and it doesnt upset
translatePath() but any recommendations to get a path all using the same divider ?

Note:: xbmc.Language( DIR_HOME ) which appends 'resources' must produce:
C:\Program Files\XBMC\scripts\<scriptname>/resources/

Is this likely to be a future problem ?

BBB


- Nuka1195 - 2009-02-17

BBB, do NOT use "/".join() for an actual path.

you use os.cwd() to get the actual current directory, so use os.path.join()

only use "/".join() when you start with a url eg "special://home/"


- BigBellyBilly - 2009-02-17

ok. will do.

Would a special:// that relates to current location ( as found with os.getcwd() ) be a useful one to have too ?


- plex - 2011-12-06

Doesn't xbmc python support SYS module
os.getcwd() doesnt always give current directory of script, it depends where the script is RUN from... even on windows or linux..

Try os.path.dirname( sys.argv[0] )


RE: Tips for coding python scripts / plugins compatible with Linux, Mac, Windows AND Xbox - Filipe Mauro - 2013-10-14

Hi, my name is Filipe, and i need some helps. Im new on XBMC development, and i dont now where can i find material to learn how to use python on XBMC.
I need do some modifications in the pythons code. Someone can help me?

Att,


This forum uses Lukasz Tkacz MyBB addons.