在python中我想从给定的路径中剪切驱动器名称,
Example:
if path given is D:\John\myfolder\newfolder
then I should get John\myfolder\newfolder
请告诉我该怎么做?我正在尝试使用os.path.abspath(路径),但这不起作用......
答案 0 :(得分:4)
In [1]: import os
In [2]: drive, tail = os.path.splitdrive(r'D:\John\myfolder\newfolder')
In [3]: tail
Out[3]: '\\John\\myfolder\\newfolder'
答案 1 :(得分:0)
你可以使用切片。
>>> path = r"D:\John\myfolder\newfolder"
>>> print(path[3:])
John\myfolder\newfolder