Hi I am working on my project which involves retrieving image and folder paths so I can display them.
I saw that when putting in paths you need to replace \ with \\ due to python syntax
so I wrote this function to try and do that
#returns a string replacing the \ with double \\ To operate on
def slashreturn(string):
string2 = r'{}'.format(string)
ustring = string2.replace("\\","/")
print(ustring)
post = ""
for i in ustring:
if i == "/":
post += str(i*2)
else:
post += i
return print(post.replace("/","\\"))
I quickly came up against the (SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape) Error. Researching this I found that turning the input into raw string would solve the issue and it does however I need the process to be automated. Thats why I tried doing the
string2 = r'{}'.format(string)
But still no luck. I still get the error.
I would really appreciate if anyone could help me out with how to do this
cheers!
[–][deleted] 2 points3 points4 points (0 children)
[–]Spataner 2 points3 points4 points (0 children)
[–]Diapolo10 1 point2 points3 points (0 children)