VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • Python 文件 IO

以下代码演示了Python基本的文件操作,包括 open,read,write:

# Filename : test.py
# author by : www.w3cschool.cn

# 写文件
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)

执行以上代码输出结果为:

该文本会写入到文件中
看到我了吧!

相关教程