File Handling

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Q Which of these files stores the values separated

by a delimiter like Comma(,)?

(a) Text Files


(b) Binary Files
(c) CSV Files
(d) TSV Files
Q Which of these will always create a new blank
binary file before writing content into it?

a) rb
b) ab
c) wb
d) None
Q To read the entire remaining contents of the file as
a string from a file object infile, we use
____________
a) infile.read(2)
b) infile.read()
c) infile.readline()
d) infile.readlines()
Q File Data
"hello! Welcome to demo file
this is testing file
for you so you can score 100/100.“

what is the output?


F= open("C:\Users\hello.txt")
a=F.readlines()
print(len(a))

a) 3
b) 2
c) 1
d) 4
Q txt = "apple#banana#cherry#orange"
x = txt.split("#”)
print(x)

a) ['apple', 'banana', 'cherry', 'orange’]


b) ['apple', 'banana', 'cherry#orange’]
c) ['apple#banana#cherry#orange']
d) No Output
Q Anjali intends to position the file pointer to the beginning
of a text file. Write Python statement for the same
assuming F is the File object .

a) F.seek(0)
b) F.seek(0,1)
c) F.seek(10)
d) F.seek(Pos=0)
Q Which of these is not a valid file
opening mode?
a) r+
b) rb+
c) r
d) rw
Q What is the command used to close
the file when all operations are done?
a) file_object.stop()
b) file_object.end()
c) file_object.over()
d) file_object.close()
Q Which module is required to work on
binary files?
a) binary
b) pickle
c) csv
d) None
Q How do you rename a file?

a) fp.name = ‘new_name.txt’
b) os.rename(existing_name, new_name)
c) os.rename(fp, new_name)
d) os.set_name(existing_name, new_name)
Q what F refers to in line below?
F= open("C:\Users\hello.txt")
print(F.readline())

a) Object
b) Variable
c) Function
d) List
Q Which of the following functions do you use to
write data in the binary format?

a) write
b) output
c) dump
d) send
Q Which type of files doesn't require any module
to be imported to be processed?

a) Regular Text Files


b) CSV Files
c) Binary Files
d) None
Q What does the readlines() method returns?

a) A single string
b) List of Strings
c) List of single characters
d) List of integers
Q Which of the following statements correctly
explain the function of seek() method?

a) tell the current position within the file


b) indicate that the next read or write
occurs from that position in a file.
c) determine if you can move the file
position or not.
d) move the current file position to a
different location at a defined offset.
Q File Data
"hello! Welcome to demo file
this is testing file
for you so you can score 100/100.“

what is the output?


F= open("C:\Users\hello.txt")
a=F.readlines()
print(type(a))

a) Int
b) String
c) Tuple
d) List
Q Which command is used to deal with run time
errors ?

a) try
b) Try
c) Test
d) TRY
Q What is the difference between r+ and w+
modes?

a) no difference
b) in r+ the pointer is initially placed at the beginning
of the file and the pointer is at the end for w+
c) in w+ the pointer is initially placed at the beginning
of the file and the pointer is at the end for r+
d) depends on the operating system
Q CSV Reader and Writers have to be created to read and
write into a csv file.

a) True
b) False
c) None
d) Padha hi nhi
Q a = open(”sample.txt","w+")
a.write("0123456789101bcdefgh")
a.seek(10)
print(a.read(2))

a) Error
b) 10
c) 1
d) gh

You might also like