views:

72

answers:

2

hi all,

I have a sorted dict

{ 1L: '<'New_Config (type: 'String') (id: 1L) (value: 4L) (name: 'account_receivable')'>', 2L: '<'New_Config (type: 'string') (id: 2L) (value: 5L) (name: 'account_payable')'>', 3L: '<'New_Config (type: 'String') (id: 3L) (value: 8L) (name: 'account_cogs ')'>', 4L: '<'New_Config (type: 'String') (id: 4L)(value: 9L)(name: 'account_retained_earning')'>', 5L: '<'New_Config (type: 'String') (id: 5L) (value: 6L) (name: 'account_income')'>' }

here new_config is object , i have to access object element

how can i access the object properties???? suppose i want to access new_config.name

+1  A: 

Python dictionaries are not sorted. If you have some custom class which implements some mapping methods (like a dictionary) but over-rides some of them to give the appearance of maintaining some (sorted) ordering then the implementation details of that might also explain why your example doesn't look like valid Python.

{
1L: New_Config(...)(...)(...)...,
2L: New_config(...)(...)(...)...,

... looks almost sorta like Python. 1L, 2L are representations of large integers (as keys if this were a dictionary). New_Config(...) looks kinda like a repr of something, and the (..) subsequent to that would be like a function call.

So, my advice is don't try to post a question from memory or from some vague notion of what you thought you saw. Actually paste in some code.

If you actually had objects there then you'd access their attributes using new_config.attribute or possibly (if someone coded up their class to be obnoxious) through some new_config.accessor() method calls (like foo.getThis() and foo.getThat() or something equally inane).

Jim Dennis
A: 
class Foo(object):
    def __init__(self,name,weight):
     self.name = name
     self.weight = weight

>>> D = {}
>>> D['1L'] = Foo("James",67)
>>> D['2L'] = Foo("Jack",83)
>>> D
{'2L': <__main__.Foo object at 0x013EB330>,
 '1L': <__main__.Foo object at 0x00C402D0>}

>>> D['1L'].name
'James'

In general,

DictName[KEY] gives you VALUE for that KEY.

so to access attribute where VALUE is an object you can use

DictName[KEY].attritbute

TheMachineCharmer
tanks for your useful submission
nazmul hasan