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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
45 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
#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)