python操作文本
>>> a = open('tmp.txt','w') #文件不存在会自动创建>>> a.write(1) #只能写字符串或者是字符流
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: argument 1 must be string or read-only character buffer, not int
>>> a.write("this is my apple!")
>>> a.close()
>>> b=open("tmp.txt",'r')
>>> b.read(500)
'this is my apple!'
>>> b.seek(0)
>>> b.readline()
'this is my apple!'
页:
[1]