Re: Convert hash to struct

2009-06-22 Thread Nick Craig-Wood
D'Arcy J.M. Cain wrote: > On Fri, 19 Jun 2009 13:17:24 -0500 > Amita Ekbote wrote: > > I am retrieving values from a database in the form of a dictionary so > > I can access the values as d['column'] and I was wondering if there is > > a way to convert the hash to a struct like format so i can

Re: Convert hash to struct

2009-06-20 Thread Steven D'Aprano
Jason wrote: > Here's my general-purpose solution for doing this: > > class Dict2Class(object): > """ > Update like a dictionary, but expose the keys as class properties. I'm afraid that's wrong. It's wrong twice: * Properties are computed attributes. These are not, they are regular att

Re: Convert hash to struct

2009-06-19 Thread Jason
Here's my general-purpose solution for doing this: class Dict2Class(object): """ Update like a dictionary, but expose the keys as class properties. Sweet! You can instantiate and update this practically any way you choose, and the values are available as class properties. >>> c

Re: Convert hash to struct

2009-06-19 Thread Dave Angel
Amita Ekbote wrote: I wanted to make a more generic way of doing this so that even if the columns are modified or new ones are added it should be simple. Anyway I will reconsider this sort of am implementation. Just out of curiosity is there any other way of achieving this? Thanks Amita On Fri,

Re: Convert hash to struct

2009-06-19 Thread Amita Ekbote
I wanted to make a more generic way of doing this so that even if the columns are modified or new ones are added it should be simple. Anyway I will reconsider this sort of am implementation. Just out of curiosity is there any other way of achieving this? Thanks Amita On Fri, Jun 19, 2009 at 1:52

Re: Convert hash to struct

2009-06-19 Thread Lie Ryan
Amita Ekbote wrote: > Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand.

Re: Convert hash to struct

2009-06-19 Thread Lie Ryan
Amita Ekbote wrote: > Hello, > > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier to read and understand.

Re: Convert hash to struct

2009-06-19 Thread D'Arcy J.M. Cain
On Fri, 19 Jun 2009 13:17:24 -0500 Amita Ekbote wrote: > I am retrieving values from a database in the form of a dictionary so > I can access the values as d['column'] and I was wondering if there is > a way to convert the hash to a struct like format so i can just say > d.column. Makes it easier

Convert hash to struct

2009-06-19 Thread Amita Ekbote
Hello, I am retrieving values from a database in the form of a dictionary so I can access the values as d['column'] and I was wondering if there is a way to convert the hash to a struct like format so i can just say d.column. Makes it easier to read and understand. Thanks Amita -- Amita Ekbote