Thursday, 18 February 2021

Data File Handling in Python

 

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

'''print("File Name=",f.name)

print("File Mode=",f.mode)

print("Is File Readable=",f.readable())

print("Is File Closed=",f.closed)

f.close()

print("Is File Closed=",f.closed)


print(f.read())

print(f.read(16))

f.read(18)

print(f.read(12))


print(f.readline(),end="")

print(f.readline(),end="")

print(f.readline(),end="")

print(f.readline(),end="")

print(f.readline(),end="")

'''

data=f.readlines()

for i in data:

    print(i,end="")

f.close()







import sys
'''f=open("ankur.txt","w")
print("Enter the content of file:\n ")
data=sys.stdin.readlines()
f.writelines(data)
print("File Created")
f.close()'''
print("The content of file:\n ")
f=open("ankur.txt","r")
print("Before Reading=",f.tell())
f.seek(10)
data=f.read()
print(data)
print("After Reading=",f.tell())
f.seek(20,0)
print(f.read())

f.close()








import pickle
f=open("ankur1.dat","wb")
data="Hello India"
pickle.dump(data,f)
f.close()
print("File create")
f=open("ankur1.dat","rb")
data=pickle.load(f)
print(data)
f.close()

No comments:

Post a Comment