<div dir="ltr">Isn't that the distinction between repr() and str()? That repr() is generally (to a greater extent) meant to return eval()-able code, while str() is just something nice to look at.<div><br></div><div style>
I don't think the # of pages it outputs should really matter, if the thing you are printing really is that big. It won't be much bigger than printing big lists or dicts, and we happily let those cause the terminal to scroll for minutes at a time if we accidentally print them. The default behavior (e.g. when you print() it or string-interpolate it) would still give you something short and nice to look at. Presumably when someone called repr() instead of str(), he was hoping for some sort of eval()-able code snippet.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Apr 30, 2013 at 6:21 PM, Guido van Rossum <span dir="ltr"><<a href="mailto:guido@python.org" target="_blank">guido@python.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">But do you really want it to print the entire parse tree even if it<br>
represents several pages of code?<br>
<div><div class="h5"><br>
On Tue, Apr 30, 2013 at 6:12 PM, Haoyi Li <<a href="mailto:haoyi.sg@gmail.com">haoyi.sg@gmail.com</a>> wrote:<br>
> Wouldn't it be nice if this<br>
><br>
>>>> import ast<br>
>>>> print repr(ast.parse("(1 + 1)").body[0].value)<br>
> <_ast.BinOp object at 0x0000000001E94B38><br>
><br>
> printed something more useful?<br>
><br>
>>>> print repr(ast.parse("(1 + 1)").body[0].value)<br>
> BinOp(left=Num(n=1), op=Add(), right=Num(n=1))<br>
><br>
> I've been doing some work on macropy, which uses the ast.* classes<br>
> extensively, and it's annoying that we have to resort to dirty-tricks like<br>
> monkey-patching the AST classes (for CPython 2.7) or even monkey-patching<br>
> __builtin__.repr (to get it working on PyPy) just to get<br>
><br>
> eval(repr(my_ast)) == my_ast<br>
><br>
> to hold true. And a perfectly good solution already exists in the ast.dump()<br>
> method, too! (It would also be nice if "==" did a structural comparison on<br>
> the ast.* classes too, but that's a different issue).<br>
><br>
> -Haoyi<br>
><br>
</div></div>> _______________________________________________<br>
> Python-ideas mailing list<br>
> <a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
> <a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/mailman/listinfo/python-ideas</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
--Guido van Rossum (<a href="http://python.org/~guido" target="_blank">python.org/~guido</a>)<br>
</font></span></blockquote></div><br></div>