سؤال

How would you handle long __repr__ strings? Is there a best practice? Lets say I've got the following.

class Foo(object):
    def __init__(self, bar):
        self.bar = bar
    def __repr__(self):
        return 'Foo(bar={0!r})'.format(self.bar)

foo = Foo(largedict)
print repr(foo)

Also is it usefull to add newlines the representation string?

هل كانت مفيدة؟

المحلول

You may find pprint form the santdard library useful.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top