简体   繁体   中英

How to fix forward slash issue in path on windows in python?

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.

os.path.join()将在正确的平台上使用正确的斜杠。

使用os.sep而不是显式写斜杠。

或者你可以使用join:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM