2010년 12월 29일 수요일

Python file write,read

File I/O for "newbie"

Not a bad site at all
#Write a file
#this opens a file named test.txt
#the string is written to the file then the file is closed
out_file = open("test.txt","w")
out_file.write("Write what you want inside here!\n")
out_file.close()
#Read a file
#open the same file, but read it this time
#read the file as string data
in_file = open("test.txt","r")
text = in_file.read()
#or text = in_file.readline()
in_file.close()
print text