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

  • Home
  • SEARCH
  • 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 528807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:01:31+00:00 2026-05-13T09:01:31+00:00

my code(i was unable to use ‘pickle’): class A(object): def __getstate__(self): print ‘www’ return

  • 0

my code(i was unable to use ‘pickle’):

class A(object):
    def __getstate__(self):
        print 'www'
        return 'sss'
    def __setstate__(self,d):
        print 'aaaa'

import pickle
a = A()
s = pickle.dumps(a)
e = pickle.loads(s)
print s,e

print :

www
aaaa
ccopy_reg
_reconstructor
p0
(c__main__
A
p1
c__builtin__
object
p2
Ntp3
Rp4
S'sss'
p5
b. <__main__.A object at 0x00B08CF0>

who can tell me how to use.

  • 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-13T09:01:31+00:00Added an answer on May 13, 2026 at 9:01 am

    What are you trying to do? It works for me:

    class A(object):
        def __init__(self):
            self.val = 100
    
        def __str__(self):
            """What a looks like if your print it"""
            return 'A:'+str(self.val)
    
    import pickle
    a = A()
    a_pickled = pickle.dumps(a)
    a.val = 200
    a2 = pickle.loads(a_pickled)
    print 'the original a'
    print a
    print # newline
    print 'a2 - a clone of a before we changed the value'
    print a2
    print 
    
    print 'Why are you trying to use __setstate__, not __init__?'
    print
    

    So this will print:

    the original a
    A:200
    
    a2 - a clone of a before we changed the value
    A:100
    

    If you need setstate:

    class B(object):
        def __init__(self):
            print 'Perhaps __init__ must not happen twice?'
            print
            self.val = 100
    
        def __str__(self):
            """What a looks like if your print it"""
            return 'B:'+str(self.val)
    
        def __getstate__(self):
            return self.val
    
        def __setstate__(self,val):
            self.val = val
    
    b = B()
    b_pickled = pickle.dumps(b)
    b.val = 200
    b2 = pickle.loads(b_pickled)
    print 'the original b'
    print b
    print # newline
    print 'b2 - b clone of b before we changed the value'
    print b2
    

    which prints:

    Why are you trying to use __setstate__, not __init__?
    
    Perhaps __init__ must not happen twice?
    
    the original b
    B:200
    
    b2 - b clone of b before we changed the value
    B:100
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to use a method when I move a piece of code
I seem to be unable to use a base class as a function parameter,
I'm unable to use native code functions as JavaScript objects in WebKit-based browsers. Is
Using Rails 3 and ActiveModel, I am unable to use the self. syntax to
I am having following code but unable to understand as to why no match
I have the following code and I am still unable to get Hibernate to
When I run my code, Unable to start activity ComponentInfo: android.database.sqlite.SQLiteException: near /: syntax
Given the next code example, I'm unable to free the parameter const char* expression
The following code produces no suitable constructor found error. I am unable to figure
I have been unable to find any decent documentation on this function. The code

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.