dmitrey a écrit :
(snip)

This doesn't stack with the following issue: sometimes user can write
in code "myObject.size = (some integer value)" and then it will be
involved in future calculations as ordinary fixed value; if user
doesn't supply it, but myObject.size is involved in calculations, then
the oofun is created to behave like similar numpy.array attribute.

IOW, you want a default value for the size if it has not been specified by the user, so you can safely use this attribute in computations. The more straightforward solution is to define this attribute (with the default value) in the initialiser, ie:


class MyClass(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.size = Whatever()


If you don't want to create as many Whatever instances as MyClass instances, you can create a single Whatever instance before defining your class:

DEFAULT_WHATEVER = Whathever()

class MyClass(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.size = DEFAULT_WHATEVER


HTH
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to