Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6111399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:37:33+00:00 2026-05-23T14:37:33+00:00

I have found previous discussing about defining Static Methods in (Iron)Python, however, I didn’t

  • 0

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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T14:37:34+00:00Added an answer on May 23, 2026 at 2:37 pm

    this answer is for python in general, and not specific to IronPython.

    property is a convenience for creating a descriptor, an object which supplies a __get__ and optionally __set__ and __del__ methods. The __get__ method accepts arguments for the target instance and also the associated class, but __set__ is never called for classes. If all you need is getter behavior without setter behavior, just implement a descriptor directly

    class StaticGetter(object):
        def __init__(self, attr):
            self.attr = attr
        def __get__(self, instance, owner):
            # owner is the class, your getter code here
            return getattr(owner, attr)
    
    class Test(object):
        __staticField = 0
        staticField = StaticGetter('_Test__staticField')
    

    In the case of a setter, you could supply a __set__ method, which infers the class from the instance, but arranging for Test.staticField = newvalue to instead call Test.staticField.someSetterMethod(newvalue) will require a new metaclass.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have found many tutorials about using Windows Server 2003 as a development machine,
I don't have enough Stack Overflow fu yet to have found a previous answer
From a previous question , I have found that it is possible to run
I have already found a previous SF question regarding this issue and I believe
I have searched and found a previous answer for this question here . The
In a continuation of my previous thread, I have found that a lot of
Reading the answers to previous questions regarding SharePoint alerts, I have found many interesting
I have found some in the Cappuccino website (vim, textmate and SubEthaEdit), but not
I have found that my HTML is, to be honest, very clunky. Small, simple
I have found some libraries or web services in PHP that does the job.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.