吆嘻!
分类: Python/Ruby
2012-04-24 23:25:27
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
input = open('data', 'r')
#第二个参数默认为r
input = open('data')
input = open('data', 'rb')
file_object = open('thefile.txt')
try:
all_the_text = file_object.read( )
finally:
file_object.close( )
file_object = open('abinfile', 'rb')
try:
while True:
chunk = file_object.read(100)
if not chunk:
break
do_something_with(chunk)
finally:
file_object.close( )
list_of_all_the_lines = file_object.readlines( )
for line in file_object:
process line
output = open('data', 'w')
output = open('data', 'wb')
output = open('data', 'w ')
file_object = open('thefile.txt', 'w')
file_object.write(all_the_text)
file_object.close( )
file_object.writelines(list_of_text_strings)注意:
追加写文件output=open('data','w+')
这个追加内容,会把原来的内容清掉。。。。
f = open('poem.txt','a')
最佳参数是 a #追加..