A.x vs. A["x"]

Martin Drautzburg Martin.Drautzburg at web.de
Sat Jan 23 12:24:44 CET 2010


Terry Reedy wrote:

> On 1/22/2010 2:29 PM, Martin Drautzburg wrote:
>> This has probably been asekd a million times, but if someone could
>> give a short answer anyways I's be most grateful.
>>
>> What is it that allows one to write A.x? If I have a variable A,
 

>> I know you can do this with classes, but not with plain objects, but
>> why is that so?
> 
> You exact meaning here is not clear, but I suspect it is somewhat
> incorrect, at least for built-in classes.

You're right. I used to think you could do this to classes:

G = Strum
G.x=1

But not to objects (instances):

g = Strum()
g.y = 2

But in fact both work. Thanks for clarifying



More information about the Python-list mailing list