How can i remove all the "" in a python string and replace them with "/"?
Question:
I wrote a python script that uses an image from the current folder which is in it and i turned it to .exe
file so i can run it without clicking on the .py
file, but if i want to give it to my friends the cwd
(current working directory) will not be the same so the string which represents mine won’t work there so i did this :
you can’t use
in python because it’s a special character in strings and in my script where i try to replace it with /
, it doesn’t work and all the script in that area becomes green as you can see and i don’t know what to do.
Answers:
The solution is simple.
Don’t do r''
but rather \
.
Here’s an example:
s= r'bruhbruhbruh' # this
s = 'bruh\bruh\bruh' # or this both work
print(s.replace('\','/'))
As people mentioned you can try with \
. for some reasons it deson’t work you can also try.
import os
strs = "somestringok"
strs = strs.replace(os.sep,'/')
print(strs)
Gives #
somestring/ok
I wrote a python script that uses an image from the current folder which is in it and i turned it to .exe
file so i can run it without clicking on the .py
file, but if i want to give it to my friends the cwd
(current working directory) will not be the same so the string which represents mine won’t work there so i did this :
you can’t use in python because it’s a special character in strings and in my script where i try to replace it with
/
, it doesn’t work and all the script in that area becomes green as you can see and i don’t know what to do.
The solution is simple.
Don’t do r''
but rather \
.
Here’s an example:
s= r'bruhbruhbruh' # this
s = 'bruh\bruh\bruh' # or this both work
print(s.replace('\','/'))
As people mentioned you can try with \
. for some reasons it deson’t work you can also try.
import os
strs = "somestringok"
strs = strs.replace(os.sep,'/')
print(strs)
Gives #
somestring/ok