参考文章http://www.ineyes.org/465-python-study-notes-4
常用参考函数http://www.cnblogs.com/rollenholt/archive/2012/04/23/2466179.html
1. 打开文件:
fileopen=open('data.txt','r') # 以读方式打开
fileopen=open('settings.ini','w') # 以写方式打开(必要时会清空这个文件)
fileopen=open('settings.ini','a') # 以追加方式打开(必要时会建立这个文件,一般用作在文件中增添新的内容)
fileopen=open('settings.ini','rb') # 用二进制读方式打开
2.读取文件
for eachline in fileopen:
print eachline
注意清除每行的回车符号strip()
3.写入文件
fileopen.write("This is a string.")
4.关闭文件
fileopen.close()