-1
在Python中我想從給定的路徑切斷驅動器名,如何從給定的路徑在python切斷驅動器名稱
Example:
if path given is D:\John\myfolder\newfolder
then I should get John\myfolder\newfolder
請告訴我該怎麼做呢?我想使用os.path.abspath則(路徑),但這是不工作...
在Python中我想從給定的路徑切斷驅動器名,如何從給定的路徑在python切斷驅動器名稱
Example:
if path given is D:\John\myfolder\newfolder
then I should get John\myfolder\newfolder
請告訴我該怎麼做呢?我想使用os.path.abspath則(路徑),但這是不工作...
In [1]: import os
In [2]: drive, tail = os.path.splitdrive(r'D:\John\myfolder\newfolder')
In [3]: tail
Out[3]: '\\John\\myfolder\\newfolder'
你可以用切片。
>>> path = r"D:\John\myfolder\newfolder"
>>> print(path[3:])
John\myfolder\newfolder