python文件写入和读取

==========================================================================   第一种方法
文件读取:
=================================================================
f1=open('beautifulSoup_test.html','r',encoding='utf8')
content_read=f1.read()
print(content_read)
f1.close()
============================================
文件写入:

=====================================
f1=open('beautifulSoup_test.html','w',encoding='utf8')
f1.write("你是写入的")
f1.close()
==========================================================
============================================================================ 第二种方法
文件的读取:
    with open("beautifulSoup_test.html",'r',encoding='utf8') as f1:
content_read=f1.read()
print(content_read)
==============================================
文件的写入:
    with open("beautifulSoup_test.html",'w',encoding='utf8') as f1:
f1.write("xxxxxxx")
================================================================


posted @ 2017-12-27 22:59  Justice-V  阅读(159)  评论(0)    收藏  举报