I often use os.path.abspath(file)
on a file address entered via the command line to sanitize it before I handle the file.
That means; performing the following:
outputPath = 'c:\Users\JEHOSHAPHAKSHAY\Desktop'
os.path.abspath(outputPath)
gives the following output:
'c:\\Users\\JEHOSHAPHAKSHAY\\Desktop'
This is in the hope that the code is more robust on different platforms and for different kinds of user inputs.
Recently I ran into an issue where this approach doesn't work as expected for a path that has one of the folders beginning with the letter t
That means; performing the following:
outputPath = 'c:\Users\JEHOSHAPHAKSHAY\Desktop\temp'
os.path.abspath(outputPath)
gives the following output:
'c:\\Users\\JEHOSHAPHAKSHAY\\Desktop\temp'
How do I get this to give me the correct path -
'c:\\Users\\JEHOSHAPHAKSHAY\\Desktop\\temp'
without doing a find and replace as that is not elegant?
Additionally, I don't mind using a raw string literal as long as I can prefix an existing string with a raw string literal.