1
我有以下腳本test.py:爲什麼python腳本的工作方式不同的Spyder的VS命令提示符
import pathlib, os
path = "C:\\Windows"
pathparent = pathlib.Path("C:\\Windows").parent
if os.path.exists(pathparent):
print("path exists")
,當我在Spyder的IDE執行它,我得到這個:
path exists
當我從命令提示符運行它(python test.py)我得到這個:
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,但我想知道的是,爲什麼在兩個環境產生不同的結果。
蜘蛛和你的提示使用不同版本的python? –
這很有趣,我添加了打印(sys.version),並且獲得了「3.6.0 | Anaconda custom(64位)|(默認,2016年12月23日,11:57:41)[MSC v.1900 64位(AMD64) ]「在Spyder中和」3.5.0 | Anaconda 2.4.0(64位)|(默認,2015年10月20日,07:26:33)[MSC v.1900 64位(AMD64)]「。 – Mike
嘗試使用v3.6.0同時運行並查看錯誤是否仍然存在 –