Monday, 2 February 2015

python 3.4.2 part 13 write and read a text file

First create file "readwritefile.py"

/****************************/


       

fw=open("sample.txt","w")
fw.write("i like to swim")
fw.close()
fr=open("sample.txt","r")
textcontent=fr.read()
print(textcontent)
fr.close()

/*********************/
1.fw is variable, it just indicate file write, you can have your own variable
2.fr is variable, it just indicate file read, you can have your own variable
3.open("sample.txt","w"). it create a text file named "sample.txt"
4.and the attribute "w" , w is predefined attribute indicating writing permission
5.and the attribute "r" , w is predefined attribute indicating reading permission
6.close() is used to avoid wastage of memory

No comments:

Post a Comment