[docs] [issue20836] Pickle Nonetype

Hans Polak report at bugs.python.org
Sun Mar 2 23:50:19 CET 2014

New submission from Hans Polak:

This simple code works, but I have two 'import pickle' lines.

The none working code has one 'import pickle' outside the class definition. This raises a Nonetype error in the pickle module, in the __del__ method. I'd like to know why and I think it's a bug, or is it?

class Login():
    users = {}
    def __init__(self):
            with open('user.data','rb') as f:
                import pickle
                self.users = pickle.load(f)
#                print('init: {}'.format(self.users))
        except Exception:
            #'user.data' file doesn't exist

    def __del__(self):
            with open('user.data','wb') as f:
#                print('del: {}'.format(self.users))
#                print(type(self.users))
#                print(type(f))
                import pickle
                pickle.dump(self.users, f, pickle.HIGHEST_PROTOCOL)
        except Exception as e:
            print('__del__ Shit happened: {}'.format(e))

assignee: docs at python
components: Documentation
messages: 212598
nosy: Hans.Polak, docs at python
priority: normal
severity: normal
status: open
title: Pickle Nonetype
type: behavior
versions: Python 3.2

Python tracker <report at bugs.python.org>

More information about the docs mailing list