[Python-ideas] Properties for classes possible?
Thomas Güttler
guettliml at thomas-guettler.de
Thu Aug 20 17:31:49 CEST 2015
Am 20.08.2015 um 17:20 schrieb Sven R. Kunze:
> Sounds more like Thomas is looking for an Pythonic solution without messing around with sys.modules or metaclasses.
>
> I personally like the proposals on StackOverflow and don't see why it couldn't be made to work out of the box:
>
>
> class MyClass:
> @classproperty
> def prop(cls):
> return '42'
The following solution provides an @classproperty:
http://stackoverflow.com/a/5191224/633961
I have not tried setting the value yet, but getting the
value works very fine.
It would be great to have "@classproperty" even in Python2. Or at least
installable via pip.
I am just a user in this case. I don't know about the best, cleanest, most efficient
way to implement this.
Regards,
Thomas
--
Thomas Guettler http://www.thomas-guettler.de/
More information about the Python-ideas
mailing list