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 1028215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:21:12+00:00 2026-05-16T12:21:12+00:00

The descriptor protocol in Python 2.6 is only defined for class definitions, and thus

  • 0

The descriptor protocol in Python 2.6 is only defined for class definitions, and thus can only be used by instances.

Is there some equivalent for instrumenting get/set of globals?

I’m trying to speed up the importing of a module which interacts with the host system, and as such has to perform some expensive probing of the host. The results of the (expensive) probe are stored in a module global that is initialized at import time; so I’m trying to delay the initialization until absolutely required.

Please, no comments about globals being evil. I know what they are and when to use them.

My current plan is to create a global instance that uses descriptors, and move all my current globals into the attributes of this instance. I expect this will work; I’m just asking if there’s another way.

  • 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-16T12:21:13+00:00Added an answer on May 16, 2026 at 12:21 pm

    My current plan is to create a global instance that uses descriptors, and move all my current globals into the attributes of this instance. I expect this will work; I’m just asking if there’s another way.

    That’s precisely what I would do. There is no equivalent to descriptors outside of classes.

    The other option, which I have also sometimes used, would be to use a function instead of a variable name, something like this:

    _expensive_to_compute = None
    def get_expensive_to_compute():
        global _expensive_to_compute
        if _expensive_to_compute is None:
            _expensive_to_compute = do_computation()
        return _expensive_to_compute
    

    If you already have a @memoize decorator defined somewhere, you can simplify the above considerably.

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

Sidebar

Related Questions

Is there something like the Python descriptor protocol implemented in other languages? It seems
How do I associate a descriptor after a class has already been defined? In
Given an arbitrary file descriptor, can I make it blocking if it is non-blocking?
I'm having some problems at runtime with some of my generated protocol buffer classes.
Is there any way to validate the Facebook Open Graph protocol meta tags in
I've got some WSDL description of a protocol which I need to implement (->
I am implementing a protocol library. Here a simplified description. The main thread within
My assembly descriptor applies the includes and excludes correctly when the dependencies are included
The web.xml Deployment Descriptor Elements in Oracle's BEA WebLogic Server 8.1 Documentation pretty much
this is a Fourier descriptor for a set of points a = -3.4173 -

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.