How to fix forward slash issue in path on windows in python?
13,730
Solution 1
os.path.join()
will use the right kind of slash on the right platform.
Solution 2
use os.sep
instead of explicitly writing the slashes.
Author by
anils
I am a software Engineer. I works in Python, JavaScript, jQuery, CSS, Pyside and PHP.
Updated on June 16, 2022Comments
-
anils almost 2 years
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.