On Sun, Dec 19, 2021 at 3:31 AM <m...@chenjt.com> wrote: > > In the following situations: > > > class Data(object): > @staticmethod > @property > def imagesTotal(): > return 10 > > print(Data.imagesTotal) > > > The "print(Data.imagesTotal)" can't print "10", it print "<property object at > 0x...>". > > It might be a good idea to use "@staticproperty" to solve this problem. > "@staticproperty" is a decorators, it mix the @staticmethod and @property. > Then the static property has getter and setter.
I'm not sure that this is actually possible the way you're doing it. The descriptor protocol (which is what makes properties work) won't apply when you're looking up statically. Your best bet, if you really need this sort of thing, would probably be to make a metaclass. But I can't advise further without a good use-case (and the example you've shown above looks extremely unpythonic). ChrisA _______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/7JH5KB3OFMOMA5FUZ42NDMJHJYEJJWQ3/ Code of Conduct: http://python.org/psf/codeofconduct/