Pickle performing class instantiation ??

Prasad, Ramit ramit.prasad at jpmorgan.com
Tue Feb 28 17:09:07 CET 2012

>class Pickle:
>    def __init__(self, Parameter1, Parameter2, Parameter3):
>        self.PM1 = Parameter1
>        self.PM2 = Parameter2
>        self.PM3 = Parameter3

>with open('/tmp/readfile.pkl', 'wb') as f:
>    pickle.dump((self.PM1, self.PM2, self.PM3), f)
>with open('/tmp/readfile.pkl', 'rb') as f:
>    self.PM1, self.PM2, self.PM3 = pickle.load(f)

>$ ./class-test1.py
>Traceback (most recent call last):
>  File "./class-test1.py", line 12, in <module>
>    pickle.dump((self.PM1, self.PM2, self.PM3), f)
>NameError: name 'self' is not defined

You need to create an instance of Pickle first and then manipulate that instance.
instance = Pickle( 'something', ['blah'],  5 )
print instance.PM1


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

More information about the Python-list mailing list