Re: Convert hash to struct

2009-06-22 Thread Nick Craig-Wood
D'Arcy J.M. Cain da...@druid.net wrote: On Fri, 19 Jun 2009 13:17:24 -0500 Amita Ekbote amita.ekb...@gmail.com 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

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

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

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 amita.ekb...@gmail.com 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

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 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 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

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 =