Possible Duplicate:
Pythonic way to check if a file exists?
如何使用 python 2.6 检查文件是否存在?
如果文件存在,则运行 exec redo.py。 如果文件不存在则执行文件start.py
文件大小为0kb,但名称为Xxx100926.csv
答案似乎是
from os path import exists
from __future__ import with_statement
if exists('Xxx100926.csv'):
from redo import main
#execfile(u'C:\redo.py')
else:
from start import main
#execfile(u'C:\start.py')
with open(Xxx100926.csv, 'a'): pass
#and run main function
main()
最佳答案
你可以将 main 函数放在 redo.py
和 start.py
中,然后
from os path import exists
if exists('Xxx100926.csv'):
from redo import main
else:
from start import main
#and run main function
main()
关于python - Python中存在文件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3805132/