Python入门 io篇

简单demo

with open('d:/pydemo/pythonStart/fun1.py', 'r') as f:
	#print(f.read())
	while True:
		line = f.readline()
		#print(line)
		if line == None or line == "" :
			break;
		# strip是去除行尾的\n,不然print会输出一行 \n又空一行
		print(line.strip())

文件读写模式

'r'	open for reading (default)
'w'	open for writing, truncating the file first
'x'	open for exclusive creation, failing if the file already exists
'a'	open for writing, appending to the end of the file if it exists
'b'	binary mode
't'	text mode (default)
'+'	open a disk file for updating (reading and writing)

参考文章

python 文件读写
python官方文档

posted @ 2019-04-09 16:02  Draymonder  阅读(111)  评论(0编辑  收藏  举报