2022-06-22 |

Python基本的文件操作,包括 ope

Python 文件 IO

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

实例(Python 3.0+)

# Filename : test.py
# author by : www.dida100.com
 
# 写文件
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)

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

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

发表评论

    评价:
    验证码: 点击我更换图片
    最新评论