我正在开发一个项目,以便使用 Python 3 学习和开发我的代码功能。在这个项目中,我需要带有路径的原始字符串。
例子:
rPaths = [r"Path to the app", r"C:\\Program Files (x86)\\MAGIX\\MP3 deluxe 19\\MP3deluxe.exe", r"F:\\VLC\\vlc.exe"]
我还需要从另一个仅包含普通列表的列表中实现这一点:
Paths = ["Path to the app", "C:\\Program Files (x86)\\MAGIX\\MP3 deluxe 19\\MP3deluxe.exe", "F:\\VLC\\vlc.exe"]
为了实现这一点,我尝试了以下方法:
rPaths1 = "%r"%Paths
rPaths2 = [re.compile(p) for p in Paths]
rPaths3 = ["%r"%p for p in Paths]
结果不理想:
>>>print(Paths)
['Path to the app', 'C:\\Program Files (x86)\\MAGIX\\MP3 deluxe 19\\MP3deluxe.exe', 'F:\\VLC\\vlc.exe']
>>>print(rPaths)
['Path to the app', 'C:\\\\Program Files (x86)\\\\MAGIX\\\\MP3 deluxe 19\\\\MP3deluxe.exe', 'F:\\\\VLC\\\\vlc.exe']
>>>print(rPaths1)
['Path to the app', 'C:\\Program Files (x86)\\MAGIX\\MP3 deluxe 19\\MP3deluxe.exe', 'F:\\VLC\\vlc.exe']
>>>print(rPaths2)
[re.compile('Path to the app'), re.compile('C:\\Program Files (x86)\\MAGIX\\MP3 deluxe 19\\MP3deluxe.exe'), re.compile('F:\\VLC\\vlc.exe')]
>>>print(rPaths3)
["'Path to the app'", "'C:\\\\Program Files (x86)\\\\MAGIX\\\\MP3 deluxe 19\\\\MP3deluxe.exe'", "'F:\\\\VLC\\\\vlc.exe'"]
谁能帮我?
我宁愿不进口任何东西。