Professional Documents
Culture Documents
FILE HANDLING
fileptr=open("file.txt","r")
if fileptr:
with open("file.txt",'r')as f:
content=f.read();
print(content)
#open the file.txt in append mode. create a new file if no such file exists
fileptr=open("file2.txt","w")
fileptr.write('''''python is the modern day language. it makes things so simple it is the faster-growing
programming language''')
#fileptr.close()
fileptr=open("file2.txt","a")
fileptr=open("file2.txt","r");
for i in fileptr:
fileptr.close()
OUTPUT
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
jfhhgkljll;;h
''python is the modern day language. it makes things so simple it is the faster-growing programming
languagepython has an easy syntax and user-friendly interaction.
2) FILE HANDLING
#Count the total number of upper case, lower case, and digits used in the
def filehandling():
data=f1.read()
cnt_ucase=0
cnt_lcase=0
cnt_digits=0
for ch in data:
if ch.islower():
cnt_lcase+=1
if ch.isupper():
cnt_ucase+=1
if ch.isdigit():
cnt_digits+=1
filehandling();
def program11():
for i in reversed(list(open("merge.txt","r"))):
print(i. rstrip())
program11()
OUTPUT:
Python 3.10.6 (tags/v3.10.6:9c7b4bd, Aug 1 2022, 21:53:49) [MSC v.1932 64 bit (AMD64)] on win32
M.DharaneeshwarI