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.
replace() method to remove the forward slashes from a string, e.g. new_string = string. replace('/', '') . The str. replace() method will remove the forward slashes from the string by replacing them with empty strings.
Programming languages, such as Python, treat a backslash (\) as an escape character. For instance, \n represents a line feed, and \t represents a tab. When specifying a path, a forward slash (/) can be used in place of a backslash. Two backslashes can be used instead of one to avoid a syntax error.
You can use forward slashes ( / ) instead of backward slashes ( \ ) on Windows (as is the case with Linux® and UNIX). If you use backward-slashes, the file name on Windows might be treated as a relative-path instead of an absolute-path.
In Python strings, the backslash "\" is a special character, also called the "escape" character. It is used in representing certain whitespace characters: "\t" is a tab, "\n" is a newline, and "\r" is a carriage return. Conversely, prefixing a special character with "\" turns it into an ordinary character.
os.path.join()
will use the right kind of slash on the right platform.
use os.sep
instead of explicitly writing the slashes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With