【发布时间】:2023-04-05 04:56:01
【问题描述】:
我想获取文件所在的目录。例如完整路径为:
fullpath = "/absolute/path/to/file"
# something like:
os.getdir(fullpath) # if this existed and behaved like I wanted, it would return "/absolute/path/to"
我可以这样做:
dir = '/'.join(fullpath.split('/')[:-1])
但是上面的例子依赖于特定的目录分隔符,并不是很漂亮。有没有更好的办法?
【问题讨论】: