Re: "literal" objects

From: Bengt Richter (bokr_at_oz.net)
Date: 12/24/03


Date: 24 Dec 2003 22:26:50 GMT

On Wed, 24 Dec 2003 09:23:23 -0800, Donn Cave <donn@u.washington.edu> wrote:

>In article <%QbGb.2109$1f6.732@newssvr25.news.prodigy.com>,
> "Moosebumps" <purely@unadulterated.nonsense> wrote:
[...]
>
>> A thought that occured to me is that classes are implemented as dictionaries
>> (correct?). So you could have a dictionary like this:
>>
>> x = {'a': 3, 'b': 5}
>> y = {'a': 5, 'b': 15}
>>
>> This would be the __dict__ attribute of an object I suppose. But I don't
>> see anyway to assign it to a variable so you could access them like x.a and
>> y.a. I don't know if this would be a "nice" way to do it or not.
>
>class A:
> def __init__(self):
> self.__dict__.update({'a': 3, 'b': 5})
>x = A()
>print x.a, x.b
>
>Would it be nice? No, it would be horrible, unless you had some
>very compelling reason to do this, in which case it would be fine.
This form of the above can be useful, though:

 class A:
     def __init__(self, **kw):
         self.__dict__.update(kw)
 x = A(a=3, b=5)
 print x.a, x.b

Since you can then also continue with

 y = A(a='Happy', b='Holidays')
 print y.a, y.b

;-)

Regards,
Bengt Richter



Relevant Pages

  • Re: disk based dictionaries
    ... Best Regards, ... >> I want to store dictionaries on disk. ... >> you are not the intended recipient, please notify the sender at Wipro or Mailadmin@wipro.com immediately ... >> and destroy all copies of this message and any attachments. ...
    (comp.lang.python)
  • Re: Best English dictionary?
    ... >> Bads include: ... >> I've been evaluating American English dictionaries on the Palm and am ... >> Concise Oxford English Dictionary with DEPReader: ... so there is no good reason for this). ...
    (comp.sys.palmtops.pilot)
  • Re: Firefox formatting glitch?
    ... Now, Thomas, don't go looking up the word ... probably a reason for this. ... dorayme, c/o Sydney. ... Arithmetic is about as irrelevant as dictionaries in this matter. ...
    (comp.infosystems.www.authoring.stylesheets)
  • Best English dictionary?
    ... I've been evaluating American English dictionaries on the Palm and am ... - Easy to use pronunciation guide (preferably with speech) ... - Pronunciation guide (though hard to interpret symbols AND a low res ... so there is no good reason for this). ...
    (comp.sys.palmtops.pilot)
  • Re: "Evidence that" ?
    ... explaining that you found them to be synonyms in the dictionary. ... (actually, three dictionaries), I used it that way because it is common ... variant should only be used when there is a reason to use it. ... "fearsome" with a variant meaning that meant the near opposite of the ...
    (alt.usage.english)