本文共 1304 字,大约阅读时间需要 4 分钟。
readlink函数
readlink -m
can get canonical file name by resolving every symlinks in every component of the given path recursively. In , the os.readlink()
function does not do so. Any equivalent function in Python to the readlink -m
line?
readlink -m
可以通过递归解决给定路径的每个组件中的每个符号链接来获取规范的文件名。 在 , os.readlink()
函数不这样做。 Python中与readlink -m
行等效的功能吗?
Specifically, it does:
具体来说,它可以:
canonicalize by following every symlink in every component of the given name recursively, without requirements on components existence
通过递归跟随给定名称的每个组件中的每个符号链接来规范化,而无需组件的存在
does 2 things:
– canonicalize by following every symlink in every component of the given name recursively, and – without requirements on components existence做两件事:
–通过递归跟随给定名称的每个组件中的每个符号链接来规范化; –无需组件存在In Python, the equivalent function is `os.path.realpath()`.
在Python中,等效函数为`os.path.realpath()` 。
One example is as follows. Note that the directory `/tmp/w` does not exist at all.
一个例子如下。 注意,目录“ / tmp / w”根本不存在。
$ ls -lhalrwxrwxrwx 1 ericma ericma 6 Nov 25 00:00 w -> /tmp/w$ readlink -f ./w/tmp/w$ readlink -f ./w/x$ readlink -m ./w/x/tmp/w/x$ python3Python 3.6.8 (default, Oct 7 2019, 12:59:55) [GCC 8.3.0] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import os>>> os.path.realpath("./w/x")'/tmp/w/x'
翻译自:
readlink函数
转载地址:http://qyowd.baihongyu.com/