# -*- coding:utf-8 -*- #
#写文件
myfile = open('hello world','w');
myfile.write('hello world');
myfile.close();
#读文件
myfile = open('hello world','r');
str = myfile.readline();
print("文件内容:\n" + str);
OutPut
文件内容:
hello world
本文介绍了一个简单的文件操作示例,包括如何使用Python进行文件的写入和读取操作。通过这个例子,读者可以了解到基本的文件操作流程。
# -*- coding:utf-8 -*- #
#写文件
myfile = open('hello world','w');
myfile.write('hello world');
myfile.close();
#读文件
myfile = open('hello world','r');
str = myfile.readline();
print("文件内容:\n" + str);
OutPut
文件内容:
hello world
3840
5007

被折叠的 条评论
为什么被折叠?