any interest in type-scoped static constants?
Paul Prescod
paulp at ActiveState.com
Sun Mar 11 17:31:15 EST 2001
Paul Miller wrote:
>
> ....
>
> Correct me if I am wrong, but do you not need an *object* of the type
> before you can call getattr on it?
>
> In other words, I would have to do this:
>
> constant_value = Point().CONSTANT_VALUE
Python type objects are not, in general, constructors.
>>> types.FloatType()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: call of non-function (type type)
Typically modules expose a function (unrelated to the type object) and
the function is the constructor. If you want, though, you could make an
object that was callable and also had a getattr.
It does seem sometimes that the constructor and the type object should
be formally related somehow (as they are for classes) but usually they
are not. I would be interested in a PEP that added *both*
getattr/setattr behavior AND callable-behavior to type objects so that
they were more like class objects.
Fixing this sort of stuff typically falls under the heading "mending the
type/class dichotomy."
http://www.google.com/search?q=class+type+dichotomy
--
Python:
Programming the way
Guido
indented it.
- (originated with Skip Montanaro?)
More information about the Python-list
mailing list