0

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?

asked Sep 24, 2013 at 10:55
0

2 Answers 2

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")
answered Sep 24, 2013 at 11:11
Sign up to request clarification or add additional context in comments.

Comments

0

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")
answered Sep 26, 2013 at 18:27

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.