File Handling
File Handling
File Handling
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.“
a) 3
b) 2
c) 1
d) 4
Q txt = "apple#banana#cherry#orange"
x = txt.split("#”)
print(x)
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) 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) 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