Python 3 教程教程
Python 文件 IO
Python 文件 IO
Python 文件 IO
Python3 实例以下代码演示了Python基本的文件操作,包括 open,read,write:
实例(Python 3.0+)
# Filename : test.py
# author by : www.verydoc.net
# 写文件
with open("test.txt", "wt") as out_file:
out_file.write("该文本会写入到文件中\n看到我了吧!")
# Read a file
with open("test.txt", "rt") as in_file:
text = in_file.read()
print(text)
执行以上代码输出结果为:
该文本会写入到文件中 看到我了吧!Python3 实例
Python 文件 IO |
---|
Python 3 教程
Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下兼容。