【发布时间】:2017-07-27 14:53:40
【问题描述】:
我在我的一个脚本中使用以下检查:
if os.path.exists(FolderPath) == False:
print FolderPath, 'Path does not exist, ending script.'
quit()
if os.path.isfile(os.path.join(FolderPath,GILTS)) == False:
print os.path.join(FolderPath,GILTS), ' file does not exist, ending script.'
quit()
df_gilts = pd.read_csv(os.path.join(FolderPath,GILTS))
奇怪的是,当路径/文件不存在时,我得到以下打印:
IOError: File G:\On-shoring Project\mCPPI\Reconciliation Tool\Reconciliation Tool Project\3. Python\BootStrap\BBG\2017-07-16\RAW_gilts.csv does not exist
告诉我,即使我添加了一个 quit(),它仍在继续执行脚本。谁能告诉我为什么?
谢谢
【问题讨论】:
-
您正在检查
FolderPath是否存在,但最后使用FILTS访问FolderPath- 完整路径是否存在? -
quit()不是 Python 内置函数。你有没有在某个地方定义它? -
@DanielRoseman 是的
-
quit()由站点模块添加。它不应该用于脚本。请参阅文档:docs.python.org/3/library/constants.html?highlight=quit#quit。我会使用sys.exit() -
这个假设似乎是错误的。