0% found this document useful (0 votes)
2 views

Textfile Program

Uploaded by

dharsitha24
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Textfile Program

Uploaded by

dharsitha24
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Text file program

f=open(“abc.txt”,’r’) s=f.read() # s is string


print(f.read()) for i in s: #taking character one by one
print(f.read().split()) condition (based on requirement in question)
print(f.readlines())
s=f.read().split() # s is list of words
This 3 lines are important for text file program for i in s:
For character by character condition(based on requirement in question)
For word by word
Line by line s=f.readlines() # s is list of lines
This is decided based on question given in for i in s:
question paper condition(based on requirement in question)

Display length five words from file Display number of vowel present in file
1)Open statement(permanent step for any file 1)open statement(permanent step for any file
program) program)
f=open(“abc.txt”,’r’) f=open(“abc.txt”,’r’)
s=f.read().split() s=f.read()
for i in s: c=0
if len(i)==5: for i in s:
print(i) if i.upper() in ‘AEIOU’:
c=c+1
f.close() print(c)

Display line which begin with vowel Word begin or line begin i[0]
1)open statement(permanent step for any file Word end i[-1]
program) Line end i.strip()[-1]
f=open(“abc.txt”,’r’)
s=f.readlines() for word in line.split():
for i in s: this loop is used if word taken from line
if i[0] in ‘AEIOUaeiou’:
print(i)
f.close()
f.read() returns in string format Student must complete the textfile worksheet.
f.readline() returns one line in string format
f.readlines() returns all lines from file

You might also like