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]
2 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]2 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
___________ is a tragic eating disturbance in which young people starve themselves because of a compulsive fear of getting fat.
Shtirlitz [24]
Anorexia nervosa is probably the most common
7 0
3 years ago
How old is the oldest person alive?
Mumz [18]

Answer:

117 years and 41 days

Kane Tanaka

can i have brainliest?

5 0
3 years ago
Read 2 more answers
The part of the presentation in which you gain attention, reveal the topic, develop credibility, relation the topic to the audie
labwork [276]
This would be the introductory of your presentation.
7 0
2 years ago
Dr. barnes tells his student charlotte that she should pursue a career that will make her happy. she responds, "not all careers
NISA [10]
Charlotte's response was an antithesis.
Antithesis is a statement which is a direct opposite of what was stated before. So, Dr. Barnes told Charlotte that she should follow her dreams and do something she loves. However, she retorts saying something quite different from his statement - telling him that what she loves won't really give her money to live from. 
4 0
3 years ago
The European Union (EU) is a cooperative political and economic alliance of European nations that began to help limit restrictio
juin [17]

Since the mid 20th century there has been a series of treaties and multilateral agreements between European countries which have led to the European Union as we know it today.

It all started as a commercial agreement to remove trade barriers for specific goods, and in 1951 the European Coal and Steel Community was created. The next step was the constitution of the European Economic Comunity (EEC) for free trade and the EURATOM Treaty to reach an agreement about nuclear energy. So far, the agreements only work towards economic integration.

But in was in 1992, in the Maastricht Treaty or Treaty of the European Union where the monetary union was designed, and also the fundamentals of the political integration of this club of countries, such as the citizenship and the common foreign and internal affairs policy. The Parliament started to have decision power.

In 1997, the treaty of Amsterdam  reformed the institutions for the arrival of new countries, and the same did the Treaty of Nice whose purpouse was to enable proper functioning with 25 member states.

The last agreement was the Treaty of Lisbon in 2009, with the objective of making the Union more democratic, giving more power to the supranational institutions and deciding which issues were left to each countries goverment and which others should be decided by the UE institutions. Nowadays the UE is formed by 28 states.

8 0
2 years ago
Read 2 more answers
Other questions:
  • Which world region contains the largest percentage of the world's street children?
    9·1 answer
  • Julie was expelled from the university for cheating. according to the student code of conduct, "any student who cheats or attemp
    7·1 answer
  • A “strong mayor” in the mayor-council system has the authority to
    12·1 answer
  • What flag indicates a hurricane warning in the water?
    15·1 answer
  • Boston and New Orleans are both Founded as
    15·1 answer
  • Which of the following is not one of Nigerians major agriculture exports?
    11·1 answer
  • John Muir argued that it would be an incalculable loss if these “temples of nature” were to be hunted, logged and mined into obl
    14·1 answer
  • One of the richest resources for the learning is the learner himself. true or false.
    5·1 answer
  • What happened during the years between the three kingdoms? ( Ancient Egypt)
    11·1 answer
  • Câu 1: Đặc điểm cơ bản của chủ nghĩa duy vật thời cổ đại trong quan niệm về vật chất là<br> gì?
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!