Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3637386
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:09:07+00:00 2026-05-19T01:09:07+00:00

I am trying to load and save objects with this piece of code I

  • 0

I am trying to load and save objects with this piece of code I get it from a question I asked a week ago: Python: saving and loading objects and using pickle.

The piece of code is this:

class Fruits: pass

banana = Fruits()    
banana.color = 'yellow'     
banana.value = 30

import pickle

filehandler = open("Fruits.obj","wb")    
pickle.dump(banana,filehandler)    
filehandler.close()

file = open("Fruits.obj",'rb')    
object_file = pickle.load(file)    
file.close()

print(object_file.color, object_file.value, sep=', ')

At a first glance the piece of code works well, getting load and see the ‘color’ and ‘value’ of the saved object.
But, what I pursuit is to close a session, open a new one and load what I save in a past session. I close the session after putting the line filehandler.close() and I open a new one and I put the rest of your code, then after putting object_file = pickle.load(file) I get this error:

Traceback (most recent call last): 
File "<pyshell#5>", line 1, in <module> 
object_file = pickle.load(file) 
File "C:\Python31\lib\pickle.py", line 1365, in load 
encoding=encoding, errors=errors).load() 
AttributeError: 'module' object has no attribute 'Fruits' 

Can anyone explain me what this error message means and telling me how to solve this problem?

Thank so much and happy new year!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:09:08+00:00Added an answer on May 19, 2026 at 1:09 am

    Python does not pickle whole classes. Only the names. Therefore you must have the module that contains them saved to a file and importable at the time they are unpickled. Python will then re-import them.

    If you run into problems, you may need to define special helper methods, __getstate__ and __setstate__ that are used for pickling.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I trying to load and save setting with this code but when I closing
What I am trying to do is load in objects from an XML save
I am trying to use Hibernate to do save/load objects that look like this
i m trying load UIImages from server asynchronously in UITableViewCell. My code worked fine
I'm trying to load some XY-coordinates from a asc-file. It looks like this: -55.988544
Here's a sample of the code, which I'm trying to load from rails c
Trying to load a small .txt file into mysql but get all my data
trying to load in a bunch of images into a list from a directory...my
When trying to load Microsoft.Xna.Framework.dll from any project, it throws a FileNotFoundException. The specified
I'm trying to use the native flex serialization/deserialization process to save/load state of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.