1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
klemol [59]
3 years ago
9

You are utilizing the pickle.load function to load objects into a program from a file. However, your program raises an exception

as soon as the end of the file is reached. What must you do?
Social Studies
1 answer:
lesantik [10]3 years ago
6 0

Answer:

When the program raises an exception as soon as the end of the is reached, this exception makes the input process difficult. We have no specific or clear way to encounter the end of the file before the exception is raised.

So to resolve this Python's try except statement can be used. This statement catches the exception and enables the program to recover. We can construct an input file loop. This loop will keep loading objects until the end of the file is detected. Below is an example to load objects from the file into a new list.

lst=list()

fileObj = open("item.dat","rb")

while True:

try:

      item= pickle.load(fileObj)

      lst.append(item)

      except EOFError:

               fileObj.close()

               break

print(lst)

The file name is item.dat and new list is named as lst. When the end of the file is encountered EOFError is raised and except clause with EOFError closes the input file and breaks out of the loop.

You might be interested in
9) An area makes most of its money through the production of plastic
JulsSmile [24]
D Economic because it’s the only one that has to do with the production of goods
5 0
3 years ago
Which canadian province is named after a part of the u.k.?
aliina [53]
Nova Scotia is a Canadian province named after a part of the UK
5 0
3 years ago
Could someone give me a list of pros and cons of imperialism in China? I am doing a History report and need some major help. I a
Pavlova-9 [17]
1. Trade imbalance with Great Britain, which led to Opium imports into China, which the Chinese tried to ban but failed. This led to the Opium Wars.

2. An outcome of the Opium wars was British victory leading to the Chinese signing unequal treaties, opening trade, giving land to the British and forcing the Chinese to pay for the war. 

3. The Europeans established 'spheres of influence' in certain territories of China, leading to the Chinese fighting back, to gain independence. 
3 0
3 years ago
What are the pros and cons of using intentionally vague language in social media and other contexts? What goals does vague langu
STALIN [3.7K]

Answer:

Are there answer choices?

Explanation:

?

6 0
3 years ago
Today many large banks offer a wide variety of financial services such as __________.
Zina [86]
The question can be rephrased as: which of the concepts listed in options are financial services?

The correct answer is: insurance (answer b). 

The other options are media-related not financial. For example, Internet is a service most typically provided by companies that specialize in internet and phone services. 
4 0
3 years ago
Other questions:
  • The best way to look at travel destinations is to look at a map.<br> True<br> False
    9·1 answer
  • Paula tumbles down the steps and twists her ankle. parker, a passerby, stops to help paula. he supports her to her car and drive
    8·1 answer
  • After maria drank coffee for the first time in her life, she felt more awake. She then begandrinking coffee every morning. Now w
    10·2 answers
  • A u.s. government official has indicated that for a generous contribution to his reelection fund, he would ignore your firm's ap
    12·1 answer
  • And the professor Latilong to game how do you professor Latilong song find a way to each archaeologists treasure
    14·1 answer
  • An environment in which managers have complete information on possible alternatives and their consequences for them to make deci
    6·1 answer
  • In general terms, how did Justice John Marshall treat issues of federalism in his Supreme Court rulings?
    10·1 answer
  • School is the symbol of civilization. Elucidate​
    8·1 answer
  • How does communication difficulty affect children of immigrants?
    11·2 answers
  • Why was the British army defeated in the American Revolution? Answers: 1. The British had to ship supplies across the ocean 2. A
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!