File Handling
file handling#1
#file1=open("puchu.txt","w")#"w" is write mode
#file1=open("puchu.txt","a")#"a" is append mode
file1=open("puchu.txt","r+")
file1.write("Puchu is a good boy\npuchu is a bad boy")
content=file1.read()
print(content)
#print(a)
file1.close()
file handling#2
with open("puchu.txt") as e:
# a = e.read(61)
# print(a)
f=open("puchu.txt","r")
a=f.read(61)
print(a)
file handling#3
file=open("C:/Users/deep1/OneDrive/Desktop/Python Programs/Text files/deep.txt","r")
#content=file.read()
#content=file.readline()
#content=file.readline()
#content=file.readline()
#content=file.readline()
content=file.read(10)
print(content)
How to clear character in file:-
truncate()
with open("harry_food.txt",'r+') as h:
for item in h:
h.truncate(0)
print(item)
Comments
Post a Comment