From the error message it is clear that the string is stored in the correct format (backslashes are escaped by doubling). So it seems the path is wrong, and the file is indeed absent.
On the other hand, in your second example that you added in your edit, you use open('c:\example2\media\uploads\test5.txt')
- this will definitely fail because \t
is a tab character (whereas all the other backslash-letter combinations don't exist, so the backslash will be treated like it was escaped correctly). But you said that the string was stored in a variable, so I don't see how this example helps here.
Consider the following:
>>> path = 'c:\example2\media\uploads\test5.txt'
>>> path
'c:\\example2\\media\\uploads\test5.txt'
See? All the backslashes are converted to escaped backslashes except for the \t
one because that's the only one with special meaning. And now, of course, this path is wrong. So if the variables you're referring to have been defined this way (and now contain invalid paths) there's not much you can do except fix the source:
>>> path = r'c:\example2\media\uploads\test5.txt'
>>> path
'c:\\example2\\media\\uploads\\test5.txt'
You might think you could "fix" a defective path afterwards like this:
>>> path = 'c:\example2\media\uploads\test5.txt'
>>> path.replace("\t","\\t")
'c:\\example2\\media\\uploads\\test5.txt'
...but there are many other escape codes (\b
, \r
, \n
etc.), so that's not really a feasible way, especially because you'd be doctoring around the symptoms instead of fixing the underlying problem.