#! /usr/bin/env python
# coding = utf-8
file_path = "/home/zjm/python_test/file_fold/hello"
f = open(file_path,"w") #write mode ,if not exits,then create one file
f.write("firstline\n")
f.write("secondline\n")
#f.flush()
f.close()
f = open(file_path,"a") #append the end
f.write("thirdline\n")
#f.flush()
f.close();
fd = open(file_path,"r") # read this fileconent
for line in fd:
print line
fd.close()
as shown above is the basic file opeartion , there have serval question that need you notice:
the first is the filepath is absolute path, otherwise there will be throws one error.
the second is every file object should be closed when you used in time.
the last one is the three operation mode , the default is "r".
this is the basic operation,then I will learn some complicated operation.