'get file path using backslash (\) in windows in python [duplicate]

How to get result exactly the same format as follows?

result = ( C:\data\a.jpg C:\data\b.jpg C:\data\c.jpg )

The following code fails:

import glob
files = glob.glob ('*.jpg')
for file in files:
  result = "C:\data\" + file


Solution 1:[1]

You can also try to split the back slash as well like this:

person_names.add(image_path_names[-1].split('/')[0].split('\\')[1])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Idevelopers geek