0% found this document useful (0 votes)
15 views16 pages

Python Data File Handling Part 01

This document contains notes on data file handling in Python. It discusses opening, reading, and writing to files. Some key points covered include: - Using open(), read(), write() and close() functions to create, read from, and write to text files - Reading/writing single lines vs entire file contents - Using readlines() to read the file into a list with each line as an element - Counting characters, words, lines and occurrences of a substring in a file

Uploaded by

bhayyavikas1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
15 views16 pages

Python Data File Handling Part 01

This document contains notes on data file handling in Python. It discusses opening, reading, and writing to files. Some key points covered include: - Using open(), read(), write() and close() functions to create, read from, and write to text files - Reading/writing single lines vs entire file contents - Using readlines() to read the file into a list with each line as an element - Counting characters, words, lines and occurrences of a substring in a file

Uploaded by

bhayyavikas1
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 16

CBSE CLASS 12 CS PYTHON

DATA FILE HANDLING


Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
Notes By: Anand Sir | YouTube Channel: CODEITUP
f=open("ram.txt","w") f=open("ram.txt","w")
name=input("Enter Your Name:") name=["Ram\n","Shyam\n","Sita\n","Gita"]
f.write(name) f.writelines(name)
f.close() f.close()
print("File Created Successfully...") print("File Created Successfully...")

Notes By: Anand Sir | YouTube Channel: CODEITUP


Notes By: Anand Sir | YouTube Channel: CODEITUP
#Read the content of a file called "Student.txt".
f=open("student.txt","r")
x=f.read()
print(x)

f=open("student.txt","r")
x=f.read(7)
print(x)
x=f.read(10)
print(x)
f.close()

#Count total number of characters in a file called


"Student.txt".
f=open("student.txt","r")
x=f.read()
print(x)
print("Total
Notes By: Anand SirNumber of Characters=",len(x))
| YouTube Channel: CODEITUP
#Count total number of vowels and consonants in a
file called "Student.txt".
f=open("student.txt","r")
x=f.read()
print(x)
v=c=0
for i in x:
if i.isalpha():
if i in 'aeiouAEIOU':
v+=1
else:
c+=1
print("Total vowel=",v,"Total consonants=",c)

Notes By: Anand Sir | YouTube Channel: CODEITUP


#Count total number of "We" in a file called
#readline
"Student.txt".
f=open("student.txt","r")
f=open("student.txt","r")
#x=f.readline()
x=f.read()
#print(x)
data=x.split()
#x=f.readline()
count=0
#print(x)
for i in data:
x=f.readline(5)
z=i.upper()
print(x)
if z=='WE':
f.close()
count+=1
print("Total Number of WE=",count)

Notes By: Anand Sir | YouTube Channel: CODEITUP


f=open("student.txt","r")
x=f.readlines()
print(x)

f=open("student.txt","r")
x=f.readlines()
print("Total Number of Lines=",len(x))
print(x)

Notes By: Anand Sir | YouTube Channel: CODEITUP

You might also like