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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:36:10+00:00 2026-06-05T21:36:10+00:00

I have one variable whose content I need to get from a remote server,

  • 0

I have one variable whose content I need to get from a remote server, so I would rather wait until its content is really needed. I thought of doing if using a property but it seems I’m doing something wrong. Follow the example.

def download():
    return 'content from remote server'

class Foo:
    def __init__(self):
        self.downloaded_bar = False
        self.bar = None

    @property
    def bar():
        if not self.downloaded:
            self.bar = download()
            self.downloaded = True
        return self.bar

f = Foo()
print f.bar #prints None, I expected 'content from remote server'

What am I doing wrong?

  • 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-06-05T21:36:12+00:00Added an answer on June 5, 2026 at 9:36 pm

    You need to make Foo a new style class for descriptors to work.
    You also can’t have a property with the same name as the attribute, so I changed .bar to ._bar
    You’ll also need to fix the typo (downloaded_bar)

    def download():
        return 'content from remote server'
    
    class Foo(object):                    # Inherit from object for new style class!
        def __init__(self):
            self.downloaded = False
            self._bar = None
    
        @property
        def bar(self):
            if not self.downloaded:
                self._bar = download()
                self.downloaded = True
            return self._bar
    
    f = Foo()
    print f.bar     def download():
        return 'content from remote server'
    

    Actually you probably don’t need the downloaded attribute at all

    class Foo(object):
        def __init__(self):
            self._bar = None
    
        @property
        def bar(self):
            if self._bar is None:
                self._bar = download()
            return self._bar
    
    f = Foo()
    print f.bar 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an integer variable ( time ) in one view controller whose value
I have one variable var1='common_location/specific_location_1/common_filename_text' now I have to get a new variable var2='common_location/specific_location_2/common_filename_text'.
I have a list of hclust objects resulting from slight variations in one variable
I have an XML variable with only one element in it. I need to
Say I wanted to have one variable in a class always be in some
I have one WORD variable in my program. WORD hour; But when I compare
I have declared one variable in xslt, assigned some value to it but while
In following program . I have one doubt. I have declared one global variable
In this C code i have tried to assign pointer addresses of one variable
I want a two-column div layout, where each one can have variable width e.g.

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.