Second attempt WAS: From Dict to Classes yes or no and how

Colin J. Williams cjwilliams43 at gmail.com
Thu Jun 24 15:03:20 EDT 2010


On 22-Jun-10 08:03 AM, Jerry Rocteur wrote:
>> On Tue, Jun 22, 2010 at 9:32 PM, Jerry Rocteur<macosx at rocteur.cc>  wrote:
>> If you were able to ask us perhaps a more specific question
>> and describe your problem a little more concisely perhaps
>> I (and we) might have a bit more to offer you.
>
> I have a dictionary:
>
> users[key] = {    'user'        : key,
>                    'secnum'      : secnum,
>                    'name'        : name
>               }
>
> Is it possible for me to code a class like this:
>
> class GRPUser(object):
>      def __init__(self, user, secnum, name, groups=None):
>          self.user          = user
>          self.secnum        = secnum
>          self.name          = name
>
> Which would allow me to iterate through and access specific records ?
>
> How do I iterate through and access an individual user record!
>
> Thanks in advance,
>
> Jerry
>
Jerry,

You are pushing your luck with so many repetitions of your posting.

First, you probably don't need the line 'user':key.  items() delivers 
this for you.

If every record has the same structure, you could work with the tuple 
(secnum, name).

It's not clear what the role of the class instance will be.

Colin W.




More information about the Python-list mailing list