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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:17:49+00:00 2026-05-15T23:17:49+00:00

suppose i have object has key ‘dlist0’ with attribute ‘row_id’ the i can access

  • 0

suppose i have object has key ‘dlist0’ with attribute ‘row_id’ the i can access as

getattr(dlist0,'row_id')

then it return value
but if i have a dictionary

ddict0 = {'row_id':4, 'name':'account_balance'}
getattr(ddict0,'row_id')

it is not work

my question is how can i access ddict0 and dlist0 same way

any one can help me?

  • 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-15T23:17:49+00:00Added an answer on May 15, 2026 at 11:17 pm

    Dictionaries have items, and thus use whatever is defined as __getitem__() to retrieve the value of a key.

    Objects have attributes, and thus use __getattr__() to retrieve the value of an attribute.

    You can theoretically override one to point at the other, if you need to – but why do you need to? Why not just write a helper function instead:

    Python 2.x:

    def get_value(some_thing, some_key):
        if type(some_thing) in ('dict','tuple','list'):
            return some_thing[some_key]
        else:
            return getattr(some_thing, some_key)
    

    Python 3.x:

    def get_value(some_thing, some_key):
        if type(some_thing) in (dict,tuple,list):
            return some_thing[some_key]
        else:
            return getattr(some_thing, some_key)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a design like this: Object GUI has two objects: object aManager
Suppose I have a customer object that has all of the standard customer properties
suppose Object A has a list of Object B, and Object B must have
Suppose I have a python object x and a string s , how do
Suppose I have a class module clsMyClass with an object as a member variable.
Suppose I have a method that takes an object of some kind as an
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]
can it make sense for one table to have multiple foreign keys? Suppose I
Suppose I have an object Person , which has_many :foos and :bars . Given
Suppose I have an array of a objects of user defined class. Wanted to

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.