Python strings
#1
What is the correct form to create strings in python for use with Windows folders that have the backslash. I am testing with a folder like L:\2 Broke Girls and sending this to JSON API for VideoLibrary.Scan() It won't work because L:\2 shows as L:\u002 Broke Girls and it doesn't work with the double backslash either. I can manually cat two string 'L:\' + '2 Broke Girls' but that will could be a coding nightmare.

Martin
Reply
#2
It should work with the double backslash.
Code:
>>> import os
>>> print repr('D:\2 Broke Girls')
'D:\x02 Broke Girls'
>>> print repr('D:\\2 Broke Girls')
'D:\\2 Broke Girls'
>>> print os.path.exists('D:\\2 Broke Girls')
True
>>> print os.path.exists('D:\2 Broke Girls')
False
My GitHub. My Add-ons:
Image
Reply
#3
Thanks for the reply. Maybe this is a JSON encoding thing, when it gets transfefred to a sqlite like statement it was failing.

Martin
Reply
#4
(2012-11-23, 16:49)emveepee Wrote: Thanks for the reply. Maybe this is a JSON encoding thing, when it gets transfefred to a sqlite like statement it was failing.

Martin

Before send in json
.replace('\\','\\\\')

Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#5
I will have to set up the test again, but I think when I tried escaping the backslash and it worked with \2 Broke Girls folder but I couldn't scan normal alpha folders.

Martin
Reply

Logout Mark Read Team Forum Stats Members Help
Python strings0