Skip to main contentSkip to solution

Arrange the following in correct order:

A. listvalues=['abc', 'Gen', 1, 2.4]

B. pickle.load(fileobject)

C. fileobject = open("file.dat","wb")

D. pickle.dump(listvalues, fileobject)

Solution

✅ Correct Option: 4

A. listvalues=['abc', 'Gen', 1, 2.4] creates the data to be stored.

C. fileobject = open("file.dat","wb") opens the file in binary write mode, which pickle needs.

D. pickle.dump(listvalues, fileobject) writes the list into the file.

B. pickle.load(fileobject) reads the stored data back, so it can only come after the data has been written.


Options 1 and 2: pickle.load comes before pickle.dump, so there is nothing in the file to read yet.

Option 3: pickle.dump comes before the file is opened and before the list exists.

In real code, close the file after dumping and reopen it in "rb" mode before calling pickle.load.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question