I agree that the %r solution is cleaner, anyway as we are talking about unicode strings (display_name, user_name etc) %r is less readable in most cases.

With "%s".encode('utf-8')

>>> DBSession.query(User).first()
<User: name=manager, email=manager@somedomain.com, display=àèìù>

With "%r"

>>> DBSession.query(User).first()
<User: name=u'manager', email=u'manager@somedomain.com', display=u'\xe0\xe8\xec\xf9'>

The .encode version might be preferred from the reader point of view

 

Last edit: Alessandro Molina 2011-06-30