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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:27:48+00:00 2026-05-25T14:27:48+00:00

I have a question that is puzzling me recently about which is the best

  • 0

I have a question that is puzzling me recently about which is the best way to retrieve attributes from outside.

Let say I have a class:

class Thing:
    def __init__(self, whatever):
        self.whatever = whatever

x = Thing('foo')

Now I know that if I want to retrieve whatever attribute I can do this:

x.whatever

I have the habit (probably because I come from other oo languages) to define methods to retrieve class attributes as needed and use them insted of retrieve them directly, like:

class Thing:
    def __init__(self, whatever):
        self.whatever = whatever

    def getWhatever(self):
        return self.whatever

In my little experience I’ve found that using this approach make things easier to mantain in the long term because if I edit the structure of data attributes I have to edit only the specific method.

But since I am not really a python veteran I’d love to know if I am doin’ it right or if some other approaches are better and more pythonic. Thoughts?

  • 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-25T14:27:49+00:00Added an answer on May 25, 2026 at 2:27 pm

    Defining explicit getters and setters is a bad practice in Python. Instead, use properties:

    class Thing(object): # New-style class
        def __init__(self, whatever):
            self._whatever = whatever
    
        @property
        def whatever(self):
            return self._whatever # Insert complicated calculation here
    

    So instead of pre-planning by using get methods, just introduce a property when you actually need advanced behavior, and not any earlier.

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

Sidebar

Related Questions

I have another very puzzling question that has cropped up after my upgrade from
I have a UI question that troubled me on the best method to handle
I have question that comes from a algorithms book I'm reading and I am
a noob question here. I have a very strange situation that's very puzzling to
i have a question that suppose i have 1 png which background is transparent
I have a question that I am a little bit confused about. I am
I have a question that if Perform search in way that i have given
I have a question that may be quite naive, but I feel the need
I have a question that I just don't feel like I've found a satisfactory
I have a question that I'm ashamed to ask, but I'm going to have

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.