close

有兩種寫法如下所示:

方法一:

f = open('test.txt', 'w')

f.write('this is a test project!!')

f.close()

 

方法二:

with open('data.txt', 'w') as f:

         f.write('this is a test project!!')

 

 

 

※方法一在大量寫入文字量時, 會出現問題, 主要是跟IO讀取有關, 有可能會造成後半的文字未被寫入

arrow
arrow
    文章標籤
    txt python
    全站熱搜

    楓綺 發表在 痞客邦 留言(0) 人氣()