I have a script that uses icons on buttons. When I leave icon.gif in the folder with the script the icons can be found without an error. But I want to keep these icons in myicons folder and use them from that folder. So the structure would be like this: myscript_folder/myicons/icon_1.gif
I have a variable that keeps the path to icons, but as you've guessed the variable has only 'icon.gif' in it.
How do I add a path to "myicons" folder to this variable which is os independent?
2 Answers 2
You can use the join function from the os.path module. This module comes in different versions for different operating systems, each using the respective file separators, etc.
import os.path
os.path.join("myicons", "icon_1.gif")
Comments
Try this, which is very same as tobias_k's reply.
import os
base_dir = r"path/to/your/myscript_folder"
print os.path.join(base_dir, "myicons", "icon_1.gif")