The following code uses the % operator to print possibly unitialized
data attributes:
------------------------8<------------------------
class J:
    name = ''
    value = ''
    def __str__(self):
        vals = self.__class__.__dict__
        vals.update(self.__dict__)
        return 'name="%(name)s" value="%(value)s' % vals

j = J()
j.name = "j object"
print j
------------------------>8------------------------

A couple of questions:
* is there a simpler or more elegant way to do this?
* how can I get this to work for new-style classes?

Thank you,
-Adam

-- 
Adam Monsen <[EMAIL PROTECTED]>
http://adammonsen.com/

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

Reply via email to