class C: def __init__(self, x): self.x = x import pickle file_ = open('c.pickle', 'rb') try: ob = pickle.loads(file_.read()) finally: file_.close()