python: read / write file

read write file by python

import os
filename = "a.py"
if os.path.isfile(filename):
    with open(filename) as f: a=''.join(f.readlines())
    #print(a)
    if a.find("break") >=0: print("found break")
    else: print("not found")

else:
    print("x")

# WRITE FILE
with open('readme.txt', 'w') as f: f.write('this is')


新增評論