7

I have developed an application in python and pyside. I have developed it on linux machine. Now I want to deploy it on windows machine. Here problem is path. In linux forward slash(/) used as separator but windows uses backward slash(\) as separator.

So, on windows all paths not work. There are several paths in application(for stylesheet, images, log etc.)

Its difficult to change all paths as most of paths are hard code like:

 rootPath()+'/static/images/add.png' #rootPath return os.path...

Example:

 colorPickerBtnStyle = 'background:url(' + rootPath() + '/static/images/color_icon.png);background-repeat: no-repeat;background-position:center center;'

Is there any work around for this problem.

5
  • 11
    When did Windows stop accepting either "/" or "\" in paths? It's allowed them since DOS. Commented May 26, 2012 at 13:08
  • 3
    The example looks like CSS, where you should always use forward slashes even on Windows anyway, even if the referenced file is local: blogs.msdn.com/b/ie/archive/2006/12/06/… Commented May 26, 2012 at 13:32
  • It's css used in desktop application using qt/pyside Commented May 26, 2012 at 14:00
  • 1
    Is it possible it's not working on Windows because of letter case insensitivity, rather than a slash direction problem? Commented May 26, 2012 at 14:00
  • -1 "all paths not work" is not useful information. I'm finding this really hard to believe. Apart from in the command prompt, you should have no problems in Windows with paths using / alone, or a mixture of / and backslash. @Anil1010, can you supply one example where you had a problem, and what the problem was? For preference, edit your question and include the actual error message and traceback. Commented May 27, 2012 at 2:13

3 Answers 3

15

os.path.join() will use the right kind of slash on the right platform.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes. That's what you sign up for when hardcoding things :)
Problem solved by using find and replace and added function assetPath which returns image path and path build using os.path.join(). Thak you Thomas!!!
Do not use hard coded paths, use os.path.join() to create path.
13

use os.sep instead of explicitly writing the slashes.

Comments

0

Alternatively you can use join:

os.sep.join((dir, file))

Comments

Your Answer

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.