21 Jun
2019
21 Jun
'19
8:25 p.m.
On Sat, Jun 22, 2019 at 11:19 AM nate lust <natelust@linux.com> wrote:
Typing this out though does make me think of an interesting idea. If there was something like __getself__ in addition to __setself__, you could implement things like MyInt. __getself__ would look something like:
class MyInt: def __init__(self, value): self.value = value def __getself__(self): return self.value def __setself__(self, value): raise ValueError("Cant set MyInt") x = MyInt(2) print(x) -> 2 type(x) -> MyInt
Now I have not really thought through how this would work, if it could work...
How does print know to call getself, but type know not to? ChrisA