每当我调用 os.path.exists(variable) 时它会返回 false,但如果我调用 os.path.exists('/this/is/my/path') 它会返回 true。
import os
import sys
test = None
print("Test directory")
test= sys.stdin.readline()
test.strip('\n')
print(os.path.exists(test))
我知道如果存在权限错误,os.path.exists 会返回 false,但我引用的目录没有限制。有时我的路径中有空格。我尝试将路径作为 '/this\is/my/path' 和 '/this is/my/path 传递,结果相同。
最佳答案
关于python - os.path.exists 不接受变量输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3954387/