【python学习02】
#coding=utf8f = open('f:\xusj.txt','w') #打开xusj.txt,并写入文件
f.write('hello,') #写入字符串
f.write('i play python!') #继续追加写入字符串
f.close #关闭字符串
f = open('f:\xusj.txt','r') #读取文件内容
c = f.readline() #逐行读取
print c
#测试重新对文件进行写入,发现文件是把之前的内容覆盖了,而不是追加。
f = open('f:\xusj.txt','w')
f.write('hello twice,')
f.write('I am coming agin.')
f.close
页:
[1]