Assigning self
inside a method simply reassigns the local name self
to another object. Assigning hologram names in Python can never change any object - they simply rewrite the names.
Why don't you use straightforward
with open("data.dat") as f: a = pickle.load(f)
instead of creating a new class? If you don't like this, wrap it in a function, but it's not so useful to put this code in __init__()
.
There are other ways to achieve the same effect. Probably the best way to achieve exactly what you are trying to do is to overwrite __new__()
instead of __init__()
- __new__()
is called before a new instance is created, so you can simply return an unallocated instance instead of having to change the already built one.
source share