Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-07-03 Thread Lie Ryan
John [H2O] wrote: > > > spir wrote: >> >> What you're looking for is a dictionary... >> s = {"cheese":"Brie", "country":"France", ...} >> >> Or maybe a kind of object type that works ~ like a dict, but with object >> syntax (get rid of {} and "" for keys). Example: >> >> class Stuff(object): >>

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-07-03 Thread John [H2O]
spir wrote: > > > What you're looking for is a dictionary... > s = {"cheese":"Brie", "country":"France", ...} > > Or maybe a kind of object type that works ~ like a dict, but with object > syntax (get rid of {} and "" for keys). Example: > > class Stuff(object): > def __iter__(self): >

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-06-26 Thread John [H2O]
Thanks everyone, all of this feedback is valuable! -- View this message in context: http://www.nabble.com/creating-a-dict-like-class---asigning-variables...-this-one-may-take-some-thought--%29-tp23759398p24218879.html Sent from the Python - tutor mailing list archive at Nabble.com. __

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-05-28 Thread Kent Johnson
On Thu, May 28, 2009 at 6:47 AM, John [H2O] wrote: > # Now I want to put them into my stuff class: >    for j in range(len(a)): >        cmd = "h.%s = a[%s][0]" % (I[j],j) >        eval(cmd) Use setattr() rather than eval. Something like setattr(h, l[j], a[j][0]) Kent

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-05-28 Thread Skipper Seabold
On Thu, May 28, 2009 at 6:47 AM, John [H2O] wrote: > > Hello, I am trying to create a class to hold and reference things similar to > matlab's structure. > > ## A class definition to hold things > class stuff(object): >    """ holds stuff """ >    def __init__(): >        pass >   �...@classmethod

Re: [Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-05-28 Thread spir
Le Thu, 28 May 2009 03:47:09 -0700 (PDT), "John [H2O]" s'exprima ainsi: > > Hello, I am trying to create a class to hold and reference things similar to > matlab's structure. > > ## A class definition to hold things > class stuff(object): > """ holds stuff """ > def __init__(): >

[Tutor] creating a dict-like class - asigning variables... this one may take some thought ; )

2009-05-28 Thread John [H2O]
Hello, I am trying to create a class to hold and reference things similar to matlab's structure. ## A class definition to hold things class stuff(object): """ holds stuff """ def __init__(): pass @classmethod def items(cls): stuff = [] for i in cls.__dict__