Python language suggestion
Martijn Faassen
m.faassen at vet.uu.nl
Sat Jan 13 11:00:48 EST 2001
Erik Max Francis <max at alcyone.com> wrote:
> Andrew Dalke wrote:
>> I believe he means
>> foo.'bar bletch'
>> as an alternate way of doing
>> getattr(foo, 'bar bletch')
>>
>> not as foo['bar bletch']
> That's not what he said. He explicitly used the subscription notation
> and even said "dictionary-like objects."
But an instance is quite a bit like a dictionary, and can be considered
to be syntactic sugar for one.
Anyway, if the proposal is what Andrew is suggesting, it's an interesting
idea, which I'm mulling over too. I don't know..
One problem seems to be the string methods. What happens here?
foo.' bar '.strip()
Also, where does it end? After all, not only strings can be used as
dictionary keys:
foo.1 = 2
Though I just checked and setattr() certainly doesn't accept:
settattr(a, 1, "foo")
It does work through __dict__ though:
a.__dict__[1] = "foo"
print a.__dict__[1]
But this seems to be of limited applicability; getattr only takes strings
too. :)
Regards,
Martijn
--
History of the 20th Century: WW1, WW2, WW3?
No, WWW -- Could we be going in the right direction?
More information about the Python-list
mailing list