file handling...



 

#note:-keep the notepad(.txt file) and the python file together..other it might show error

#thank you...byeee



print("file handling practise")



#how to open a file

f = open("faizan.txt","a")

#let me show u some more extra program..

#first keep the in append mode only ('a')

#in this program first it will add the content in the file..then it will print the content ..

t = f.write("\n hello everyone ..this is just for practise purpose")

f.close()

f = open("faizan.txt","r")

o = f.read()

print(o)

f.close()






#a means append mode yai writing mode jaisa he hai but

#writing mode meh previous text hatt jata tha isme previous text k saat show hota hia

t=f.write("\n hello hope you all understand this")

f.close()


#r means the file is in reading mode --iska matlub jo bhi file k andar hoga woh print hoga

t = f.read()

print(t)

f.close()

#note:-jab bhi file open karre ho toh last meh yai close lagao...

#zaruri nahi hai but as a programmer accha hota hai



#w means the file is in writing mode

f.write("hello friends this is me")

#what ever we wil write here will overwrite the previous text in the file like i show u again

f.close()



Comments