如何使用python 2.6检查文件是否存在?
如果文件存在,请运行exec redo.py. 如果文件不存在exec文件start.py
该文件为0kb,但名称为Xxx100926.csv
Ans似乎是
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()
答案 0 :(得分:3)
您可以将主要功能放在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()