Quiz on file handling

  1. Select all true statements when a file is opened using the with statement
    a). The with statement simplifies exception handling
    b). The file is automatically closed after leaving the block, and all the resources that are tied up with the file are released.
    c). File reading and writing are faster using the with statement.

  2. Select all correct methods to copy the source file’s content to the destination file

a)shutil.copy()
b)shutil.copy2(src_path, dst_path)
c)shutil.copyfileobj()
d)shutil.copyfile()`

  1. Select the correct mode to open a file for appending as well as reading

a) a+
b) ar
c) rw
d) ar+

  1. Select the correct access mode to open a file only for exclusive creation
    a) t
    b)w
    c) x
    d) a

  2. Which method is used to read file line by line

a)read(1)
b)readlines(1)
c)readline()
d)line()

6.Select the correct output of the following code

fp.seek(5, 1)

a)Move file pointer five characters ahead from the current position.
b)Move file pointer five characters ahead from the beginning of a file.
c)Move file pointer five characters behind from the current position.
d)Move file pointer five characters behind ahead from the end of a file.

1 Like
  1. a, b
    2)a, b, d
  2. a
  3. c
  4. c
  5. a
1 Like

1)a,b
2)all the above
3)a
4c
5)c
6)a

1 Like

1 a)
b)

2 a)
b)
d)

3 a)

4 c)

5 c)

6 a)

1 Like
  1. a, b
  2. a, b, d
  3. a
  4. c
  5. c
  6. a
1 Like

Kindly cross check your answers with below

  1. a,b
    2)a,b,c,d
    3)a
    4)c
    5)c
    6)a

I have posted the answers in reply. cross-check

I have posted the answers in reply. cross-check

I have posted the answers in reply. cross-check

I have posted the answers in reply. cross-check