Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在python中从给定路径剪切驱动器名_Python - Fatal编程技术网

如何在python中从给定路径剪切驱动器名

如何在python中从给定路径剪切驱动器名,python,Python,在python中,我想从给定路径中剪切驱动器名 Example: if path given is D:\John\myfolder\newfolder then I should get John\myfolder\newfolder 请告诉我怎么做?我正在尝试使用os.path.abspath(path),但无法使用…: 你可以用切片 >>> path = r"D:\John\myfolder\newfolder" >>> print(path[3:])

在python中,我想从给定路径中剪切驱动器名

Example:
if path given is D:\John\myfolder\newfolder
then I should get John\myfolder\newfolder
请告诉我怎么做?我正在尝试使用os.path.abspath(path),但无法使用…

你可以用切片

>>> path = r"D:\John\myfolder\newfolder"
>>> print(path[3:])
John\myfolder\newfolder
>>> path = r"D:\John\myfolder\newfolder"
>>> print(path[3:])
John\myfolder\newfolder