On Wed, Aug 5, 2020 at 1:54 PM David Mertz
On Wed, Aug 5, 2020 at 1:27 PM Ricky Teachey
wrote: On Wed, Aug 5, 2020 at 11:41 AM Marco Sulla
wrote: On Wed, 5 Aug 2020 at 15:53, Ricky Teachey
wrote: from mypython import * @const a = 5 I'm probably dim but I have no idea what that is supposed to mean or do. Is this just calling const(a=5)...? what is the point of that?
I'm not advocating it, and I'm not the one that came up with it. But my impression is that it is intended to mean:
a = const('a', 5)
This doesn't seem completely pointless:
class const(): ... def __init__(self, name, val): ... self.name = name ... self.val = val ... def about(self): ... print(self.name, '=', self.val) ... a = const('a', 5) a.val 5 a.about() a = 5
There might be a way to subclass, e.g. int, so that you don't need to use `a.val` to get the value. It wasn't obvious to me how to do it in pure Python with 3 minutes thought.
Ah, I get it. And btw this works:
class const(int): ... def __new__(cls, name, val): ... obj = super().__new__(cls, val) ... obj.name = name ... return obj ... def about(self): ... print(self.name, '=', self) ... a = const('a', 5) a 5 a.about() a = 5
--- Ricky. "I've never met a Kentucky man who wasn't either thinking about going home or actually going home." - Happy Chandler