3

我想替换file_location = os.path.abspath(os.path.dirname(__file__))pathlib获取没有文件名的文件 的绝对路径
,使用 directorypath = pathlib.Path(__file__).resolve() 给我绝对路径+文件名
我怎样才能获得没有文件名的绝对路径?

4

1 回答 1

5

你可以使用'.parent': directorypath = pathlib.Path(__file__).resolve().parent
Path.parent

于 2020-08-27T13:41:15.520 回答