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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:37:10+00:00 2026-06-09T15:37:10+00:00

In C-ish languages, I’d mask data storage details with getter/setter methods/functions like: int getFoo();

  • 0

In C-ish languages, I’d mask data storage details with getter/setter methods/functions like:

int getFoo();
void setFoo(int value);

I have some Python that does:

class MyClass:
    def Foo(self):
        ...magic to access foo...
        return value

What’s the right way to write/name a setter for Foo? I’m sure it’s more idiom than language feature but I’m not sure what’s common. Maybe I need to rename Foo() to getFoo() and match it with setFoo(). I guess that’s OK if that’s what is usually done.

  • 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-09T15:37:12+00:00Added an answer on June 9, 2026 at 3:37 pm

    Use the builtin property function:

    class MyClass:
    
        def __init__(self):
            self._value = 'Initialize self._value with some value or None'        
    
        def get_foo(self):
            ...magic to access foo...
            return self._value
    
        def set_foo(self, value):
            ... magic processing for value ...
            self._value = value
    
        foo = property(get_foo, set_foo)
    

    Now you can use access it like this:

    inst = MyClass()
    inst.foo = 'Some value'
    print inst.foo
    

    It will print:

    ‘Some value’

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

Sidebar

Related Questions

I have a long-ish script to do some data analysis, and it has to
Are there any compilers out there for function or lisp-ish languages that compile to
I consider myself fairly competent in understanding and manipulating C-ish languages; it's not a
I have a large(ish - >100K) collection mapping a user identifier (an int) to
I have a large-ish project that I'm working on which uses git as the
I have and old(ish) C# method I wrote that takes a number and converts
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into
I have a large-ish PHP project (hundreds of files) that I've been brought in
Is there an easy-ish way to modify the webform-form-tpl.php template to show disclaimer text
Please excuse the noob-ish nature of this question. I have a project in which

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.