1、文件操作:
def wfile():
try:
filename="C:\\users\\h3c\\"+"test.html"
except IOError:
print("file create error")
else:
fp=open(filename,'wb')
fp.write("test".encode('utf_8'))
fp.close()
def rfile():
try:
filename="C:\\Users\h3c\\"+"test.html"
fp=open(filename,'r')
except IOError:
print("file open error")
else:
for f in fp:
print("file data is "+f)
fp.close()
if __name__=='__main__':
wfile()
rfile()
print('Done!')