Making Variable Text Output More Pythonic?

Casey McGinty casey.mcginty at gmail.com
Thu May 15 04:32:01 EDT 2008


Hi,

I have some classes that print variable outputs depending on their internal
state, like so:

def __str__(self):
    out = []
    if self.opt1: out += ['option 1 is %s' % self.opt1']
    if self.opt2: out += ['option 2 is %s' % self.opt2']
    ....
    return '\n'.join(out)

Is there any way to make this cleaner?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080514/fbaa3536/attachment.html>


More information about the Python-list mailing list