python:if else 语句

#!/usr/bin/python
# -*- coding:utf-8 -*-

import os

fileName1 = 'a.txt'
if os.path.exists(fileName1):
file1 = open(fileName1,'w')
file1.write('file1 exists')
else:
file1 = open(fileName1,'w')
file1.write('file1 not exists')

posted @ 2019-10-15 16:37  流星曳尾  阅读(200)  评论(0编辑  收藏  举报