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):
>>
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):
>
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.
__
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
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
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__():
>
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__