Unit 8 : File Processing Flashcards

1
Q

What does open() returns?

A
  1. “file handle” - a variable used to perform operations on the file
  • LIke “File -> Open” in a aword processor
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does open() accepts? ( 2 )

A

handle = open( filename, mode )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the mode for file handle?

A
  1. r - to open a file for reading
  2. w - to open a file for writing if file exist, otherwise create a file
  3. a - to open a file for append if file exist, otherwise create a file
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What can we seperate the data?

A
  1. Using seperator ( , )
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How can we write into file?

A

name = input(“Name : “)
f = open(“user.txt”, “a”)
f.write(name)
f.close
print(“Record Added”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How can we read from file?

A

f = open(“user.txt” , “r” )
for line in f:
print(line)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How can we count line in a file?

A

f = open(“user.txt”)
count = 0
for line in f:
count = count + 1
print(“Line Count : “ , count )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How can we search through a file? ( .startswith )

A

f = open(“user.txt”, “r”)
for line in f:
if line.startswith(“Jill”):
print(line)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How can we search through a file? ( rstrip() )

A

f = open(“user.txt” , “r” )
for line in line:
line = line.rstrip()
print(line)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How can we skip a lline?

A

f = open(“user.txt”,”r”)
for line in f:
line = line.rstrip()
if line.startswith(“Jack”):
continue
print(line)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How can we select line ( in ) ?

A

f = open (“user.txt”, “r”)
for line in f:
line = line.rstrip()
if “jim@mail.com” in line:
print(line)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly