"""
Version: 0.1
Author: freshbin
Date: 2019年8月21日
"""
print("=================================文件 start================================================")
poem = '''\
Programming is fun
When the work is done
if you wanna make your work alse fun:
use Python!
'''
# 打开文件以编辑('w'riting)
f = open('poem.txt', 'w')
# 向文件中编写文本
f.write(poem)
# 关闭文件
f.close()
# 如果没有特别指定
# 将假定启用默认的阅读('r'ead)模式
f = open('poem.txt')
while True:
line = f.readline()
# 零长度指示 EOF
if len(line) == 0:
break
print(line, end='')
# 关闭文件
f.close()
print("=================================文件 end================================================")
print("=================================Pickle start================================================")
import pickle
shoplistfile = 'shoplist.data'
shoplist = ['apple', 'mango', 'carrot']
f = open(shoplistfile, 'wb')
pickle.dump(shoplist, f)
f.close()
del shoplist
f = open(shoplistfile, 'rb')
storedlist = pickle.load(f)
print(storedlist)
print("=================================Pickle end================================================")
print("=================================Unicode start================================================")
import io
f = io.open("abc.txt", "wt", encoding="utf-8")
f.write(u"Imagine non-English language here")
f.close()
text = io.open("abc.txt", encoding="utf-8").read()
print(text)
print("=================================Unicode end================================================")