このコードを実行しようとすると:
from pprint import PrettyPrinter
class MyPrettyPrinter(PrettyPrinter):
def __init__(self, *args, **kwargs):
PrettyPrinter.__init__(self, *args, **kwargs)
def format(self, object, context, maxlevels, level):
(repr, readable, recursive) = PrettyPrinter.format(self, object, context, maxlevels, level)
return (type(repr)(object), readable, recursive) if isinstance(object, str) else (repr, readable, recursive)
print(MyPrettyPrinter().pformat(['x']))
Python 3 ( ) では、Python 2 ( )とは異なる出力が得られます。['x']
[x]
これはなぜですか? また、Python 2 と同じ動作を得るにはどうすればよいですか?