Python中是否存在文件?

2024-06-17 14:54:14 发布

您现在位置:Python中文网/ 问答频道 /正文

Possible Duplicate:
Pythonic way to check if a file exists?

如何使用Python2.6检查文件是否存在?

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

Tags: 文件csvfrompyimportifmainwith
1条回答
网友
1楼 · 发布于 2024-06-17 14:54:14

您可以将main函数放在redo.pystart.py中,然后

from os path import exists

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

#and run main function
main()

相关问题 更多 >