python练习(三)
1. 把一个数字的list从小到大排序,然后写入文件,然后从文件中读取出来文件内容,
然后反序,在追加到文件的下一行中
list = [67, 234, 35, 14, 18, 6, 9, 5]
list.sort()
with open('20171030','w') as f:
f.write(str(list)+'\n')
with open('20171030','r') as f:
a=f.read()
list.reverse()
with open('20171030','a') as f:
f.write(str(list))
2.分别把 string, list, tuple, dict写入到文件中
string = 'awen'
list=[1,2,3,4,5,6]
tuple=(1,2,3,4,5,6)
dict={'q':1,'a':2,'z':3}
with open('20171030', 'w') as f:
f.write(string+'\n')
f.write(str(list)+'\n')
f.write(str(tuple)+'\n')
f.write(str(dict)+'\n')