我有以下脚本测试.py:
import pathlib, os
path = "C:\\Windows"
pathparent = pathlib.Path("C:\\Windows").parent
if os.path.exists(pathparent):
print("path exists")
当我在Spyder IDE中执行它时,我得到的是:
^{pr2}$Traceback (most recent call last):
File "test.py", line 6, in <module>
if os.path.exists(pathparent):
File "C:\Anaconda3\lib\genericpath.py", line 19, in exists
os.stat(path)
TypeError: argument should be string, bytes or integer, not WindowsPath
你知道为什么我得到不同的结果吗?在
注意:我知道在str()中包装pathparent会使if语句成功,但我想知道的是为什么这两个环境会产生不同的结果。在
os.path.exists()
开始接受python3.6中的path对象,当运行python3.5时,您的cmd提示出现问题,请将其更改为3.6以解决问题。在相关问题 更多 >
编程相关推荐