python文件操作(1)

# -*- 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)