gpt4 book ai didi

python - 检查目录是否是python 2.7的挂载点

转载 作者:太空狗 更新时间:2023-10-29 20:41:46 25 4
gpt4 key购买 nike

是否有一种 pythonic 方式并且没有 shell 命令(即使用 subprocess 模块)来检查目录是否是挂载点?

到目前为止,我使用:

import os
import subprocess

def is_mount_point(dir_path):
try:
check_output([
'mountpoint',
path.realpath(dir_name)
])
return True
except CalledProcessError:
return False

最佳答案

有一个os.path.ismount(path) .

Return True if pathname path is a mount point: a point in a file system where a different file system has been mounted. The function checks whether path‘s parent, path/.., is on a different device than path, or whether path/.. and path point to the same i-node on the same device — this should detect mount points for all Unix and POSIX variants.

import os
os.path.ismount(dir_name) # returns boolean

您也可以引用implementation (如果您使用的是 POSIX 系统)。检查其他平台的 macpath.pyntpath.py

关于python - 检查目录是否是python 2.7的挂载点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39124363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com