8、Python —— 输入输出

>

1、使用文件

# encoding: utf-8
# !/usr/bin/python
# Filename : helloworld.py

peom = ‘‘‘如梦令 李清照
常记溪亭日暮,
沉醉不知归路。
兴尽晚回舟,
误入藕花深处。
争渡,争渡,
惊起一滩鸥鹭。‘‘‘

# 模式可以为读模式(‘r‘)、写模式(‘w‘)或追加模式(‘a‘)
f = file(‘peom.txt‘, ‘w‘)	# open for ‘w‘riting
f.write(peom)
f.close()

# 默认是读模式
f = file(‘peom.txt‘)
while True:
	line = f.readline()
	if len(line) == 0:
		break
	print line
f.close()




8、Python —— 输入输出,布布扣,bubuko.com

8、Python —— 输入输出

上一篇:Eclipse编辑java文件报Unhandled event loop exception错误的解


下一篇:Java Magic. Part 4: sun.misc.Unsafe