Q: attribute access and comparisons of two different objects
Aahz
aahz at pythoncraft.com
Tue Jun 15 14:57:30 EDT 2004
In article <2418de8e.0406150420.1c1bde76 at posting.google.com>,
Chris... <chris.schaller at web.de> wrote:
>
>1) Is there already a "fix" to avoid writing to an attribute that
>isn't defined yet? I remember this being an often discussed problem,
>but didn't see any changes. The only way I can think of is overriding
>__setattr__, but this is huge overhead. While I like the idea of
>being able to add new attributes on the fly, in great projects I'd
>like to restrict some classes not to do so.
Don't use __slots__. Why do you think __setattr__ is a huge overhead?
>2) This is driving me nuts: I do not want to compare apples and peas.
>I can say that they are not equal, but I cannot say that one is great
>than the other (speaking not of greater taste ;-). Just ran into a
>problem caused by comparing a string with a number ("1" > 10) -- I
>simply forgot to convert the string to an integer. Since I cannot add
>"1" + 10 which makes sense, I do not want to compare them. Any
>development regarding this? Any """from __future__ import"""?
You'll have to wait for Python 3.0 for the core to fully support this;
meanwhile, you can only force this with your own classes.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"as long as we like the same operating system, things are cool." --piranha
More information about the Python-list
mailing list