python基础5--文件操作--字符串读写

代码
# file's name : using_file.py

info 
= """My name is nami, I'm from HuBei province,
I like TVB television very much, but now I'm in CS
"""

filename 
= "c:/nami.txt"

# write info to file
= file(filename, "w")
f.write(info)
f.close()
print "Info saved successed!"

# read info from file
= file(filename, "r")
print "The info are as follow:"
while True:
    line 
= f.readline()
    
if len(line) == 0:
        
break
    
print line,

f.close()

输出结果:
Info saved successed!
The info are as follow:
My name is nami, I'm from HuBei province,
I like TVB television very much, but now I'm in CS

posted on 2010-11-15 22:41  TroyZ  阅读(225)  评论(0编辑  收藏  举报