What does open() returns?
What does open() accepts? ( 2 )
handle = open( filename, mode )
What are the mode for file handle?
What can we seperate the data?
How can we write into file?
name = input(“Name : “)
f = open(“user.txt”, “a”)
f.write(name)
f.close
print(“Record Added”)
How can we read from file?
f = open(“user.txt” , “r” )
for line in f:
print(line)
How can we count line in a file?
f = open(“user.txt”)
count = 0
for line in f:
count = count + 1
print(“Line Count : “ , count )
How can we search through a file? ( .startswith )
f = open(“user.txt”, “r”)
for line in f:
if line.startswith(“Jill”):
print(line)
How can we search through a file? ( rstrip() )
f = open(“user.txt” , “r” )
for line in line:
line = line.rstrip()
print(line)
How can we skip a lline?
f = open(“user.txt”,”r”)
for line in f:
line = line.rstrip()
if line.startswith(“Jack”):
continue
print(line)
How can we select line ( in ) ?
f = open (“user.txt”, “r”)
for line in f:
line = line.rstrip()
if “jim@mail.com” in line:
print(line)