开发者

Does File exist in Python? [duplicate]

This question already has answers here: 开发者_JAVA百科 Closed 12 years ago.

Possible Duplicate:

Pythonic way to check if a file exists?

How can Check if file exist with python 2.6?

If file exists run exec redo.py. If file does not exists exec file start.py

The file is a 0kb, but name Xxx100926.csv

Ans seems to be

 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()


you can put main function in redo.py and start.py and then

from os path import exists

if exists('Xxx100926.csv'):
  from redo import main
else:
  from start import main

#and run main function
main()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜