close
# wirte DATA to a file
f = open('../test.dat','w')
omg="this is a test!"
f.write(omg) # wirte for 字串 only
print >>f, 1+1 # print for everything included number
f.close()
test.dat
this is a test!
2
# read DATA from file
inf = open('../test.dat','r')
inf.read
this is a test!\n2\n #讀進來的結果print在螢幕上的
inf.read
' ' #表示已到文件的底部
inf.close()
'w' : write
'r' : read
'a':在檔案的尾端加入東西
'r+':可以讀也可以寫
全站熱搜
留言列表