I have found previous discussing about defining Static Methods in (Iron)Python, however, I didn't find any about Static Properties. I assume you can definitively create Static Properties since properties are just methods for the .NET CLR and that's what I did in the code below, however, it looks like by calling the Static Property "StaticField" I cannot access the value of the Static Field "__staticField" it is linked to instead I get a reference where the property is stored? , but If I use the Static Method "getStaticField" that is used as the Get Property it does correctly give me the value "2".
So the question is: can you define Static Properties in (Iron)Python? and how can I use them to get the value and not the reference to the property method?
Thanks in advance.
class Test(object):
__instanceField = 0
__staticField = 0
# Instance Property (read-only)
def getInstanceField(self):
return self.__instanceField
InstanceField = property(getInstanceField, None, None)
# Static Property (read-only)
@staticmethod
def getStaticField():
return Test.__staticField
StaticField = property(getStaticField, None, None)
# Instance Method
def instanceMethod(self, n):
self.__instanceField += 1
print 'instanceMethod', n
# Static Method
@staticmethod
def staticMethod(n):
Test.__staticField += 1
print 'staticMethod', n
# Calling Static Methods
Test.staticMethod(5)
Test.staticMethod(10)
# Calling Instance Methods
t = Test()
t.instanceMethod(5)
t.instanceMethod(10)
print 'InstanceProperty', t.InstanceField
#prints 2
print 'StaticProperty', Test.StaticField
#prints: <property object at 0x000000000000002B>
print 'StaticPropertyMethod', Test.getStaticField()
#prints 2