1

可能重复:
检查文件是否存在的 Pythonic 方法?

python 2.6如何检查文件是否存在?

如果文件存在,则运行 exec redo.py。如果文件不存在 exec 文件 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()
4

1 回答 1

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()
于 2010-09-27T15:39:33.317 回答