def html_rep(obj):
    """Format an object in an html-friendly way. That is; convert any < and > characters
    found in the str() representation to the corresponding html-escape sequence."""
    
    s = str(obj)
    if s == '':
        s = repr(obj)            
    return s.strip().replace('<','&lt;').replace('>', '&gt;')