【发布时间】:2019-04-30 18:29:11
【问题描述】:
在某些时候,波浪符号 ~ 不再被识别为我的主目录,仅在 Python 中。 〜仍然可以在终端中使用,所以我不确定发生了什么,但是任何有关如何修复它的见解都会为我节省一些打字谢谢!
在 macOS Mojave 上
import os
tilde = '~'
print(os.path.exists(tilde))
os.system("if test -d ~; then echo 'exists'; fi")
输出:
False
exists
【问题讨论】:
-
波浪号是 shell 识别的快捷方式,而不是主目录的替代名称。
标签: python macos unix terminal environment-variables