G 1: To Read Total Data From The File
G 1: To Read Total Data From The File
txt",'w')
f=open("abcd.txt",'w')
f.write("Durga\n")
f.write("Software\n")
f.write("Solutions\n")
print("Data written to the file successfully")
f.close()
f=open("abcd.txt",'w')
list=["sunny\n","bunny\n","vinny\n","chinny"]
f.writelines(list)
print("List of lines written to the file successfully")
f.close()
f=open("abc.txt",'r')
ine1=f.readline()
print(line1,end='')
line2=f.readline()
print(line2,end='')
line3=f.readline()
print(line3,end='')
f.close()
f=open("abc.txt",'r')
lines=f.readlines()
for line in lines:
print(line,end='')
f.close()
Eg 5:
f=open("abc.txt","r")
print(f.read(3))
print(f.readline())
print(f.read(4))
print("Remaining data")
print(f.read())
with open("abc.txt","w") as f:
f.write("Durga\n")
f.write("Software\n")
f.write("Solutions\n")
print("Is File Closed: ",f.closed)
print("Is File Closed: ",f.closed)
f=open("abc.txt","r")
print(f.tell())
print(f.read(2))
print(f.tell())
print(f.read(3))
print(f.tell())
import os,sys
fname=input("Enter File Name: ")
if os.path.isfile(fname):
print("File exists:",fname)
f=open(fname,"r")
else:
print("File does not exist:",fname)
sys.exit(0)
print("The content of file is:")
data=f.read()
print(data)
import pdb
var=10
pdb.set_trace()
a=int(input("enter the a string"))
b=int(input("enter the b value"))
sum=a+b
print(sum)
def add(a, b):
return a + b
def samplefunc():
var = 10
print("One. Line 1 ..")
print("Two. Line 2 ..!")
out = add(20, var)
print('Three. Line 3 .. Done!')
return out
print(samplefunc())