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 "".
It might be a good idea to use "@staticproperty" to solve this problem.
"@staticprope
On Sun, Dec 19, 2021 at 3:31 AM 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 " 0x...>".
>
> It might be a
I'm confused about what a staticproperty would even be.
Usually, properties are a way to provide an interface that "looks like" a
simple attribute, but does some computation under the hood. But that
computation usually requires instance data to do its thing -- so a static
one wouldn't be useful.
All that is needed is a descriptor which calls the decorated functiosn
without any parameters.
This could serve to use classes as namespaces for "live" globals - if one
will do some sort
of reactive programing, it might even find some use.
A descriptor with a for that would be something like:
If the goal is to create a "property" that behaves like such but doesn't
receive "self" as a parameter, the straightforward way to do so would be a
simple descriptor.
class StaticProperty:
def __init__(self, fget=None, fset=None, fdel=None):
self.fget = fget
self.fset = fset
On 12/18/21 08:44, Stephen J. Turnbull wrote:
Hao Hu writes:
> > On 17 Dec 2021, at 15:28, Chris Angelico wrote:
> > The built-in hash() function is extremely generic, so it can't really
> > work that way. Adding a parameter to it would require (a) adding the
> > parameter to every __h
By way of correcting misconceptions:
On 12/18/21 8:39 AM, Chris Angelico wrote:
>
> 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.
On 12/18/21 9:19 AM, Christoph
On Sun, Dec 19, 2021 at 8:10 AM Ethan Furman wrote:
>
> By way of correcting misconceptions:
>
> On 12/18/21 8:39 AM, Chris Angelico wrote:
> >
> > 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
> > a
Thank everyone!
I just want to use a class that holds global variables and has a value that can
be easily calculated. So I thought it would be more elegant to use
"@staticproperty".
These is just my personal thought and not necessary. Now you've given me the
solution.
__