You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I would be nice if ggplot objects had a __str__ method that draws the plot without the <ggplot:hash> annotation. For pretty printing, users could then write print(p) and for debugging print(repr(p)) would still be available.
What is your main working environment? Jupyter-notebook, pycharm, ... ? If not jupyter-notebook (it uses __repr__), does it use __str__ or __repr__ for printing the last statement of a code block/cell?
I am working in a Jupyter-notebook but from within Visual Studio Code. If Jupyter-notebook would call __repr__ then I can still do print(str(p)) and then print(p) would even be backwards compatible so that existing user code is unaffected.
AFAIK, currently, print(p) does the same as repr(p), so the two primitives would be repr(p) and str(p) and users can forget about doing print(p) altogether, except to do more complicated printing.
Activity
has2k1 commentedon Oct 29, 2020
What is your main working environment? Jupyter-notebook, pycharm, ... ? If not jupyter-notebook (it uses
__repr__), does it use__str__or__repr__for printing the last statement of a code block/cell?rhalbersma commentedon Oct 29, 2020
I am working in a Jupyter-notebook but from within Visual Studio Code. If Jupyter-notebook would call
__repr__then I can still doprint(str(p))and thenprint(p)would even be backwards compatible so that existing user code is unaffected.has2k1 commentedon Oct 30, 2020
So, this is how the cases would turn out
repr(p)- Show Plot, Return'<ggplot:hash>'str(p)- Show Plot, Return''print(p)- Show Plot, Print''print(str(p))- Show Plot, Print''am I missing anything?
rhalbersma commentedon Oct 30, 2020
AFAIK, currently,
print(p)does the same asrepr(p), so the two primitives would berepr(p)andstr(p)and users can forget about doingprint(p)altogether, except to do more complicated printing.has2k1 commentedon Oct 30, 2020
Yes that is the case; and it is what is going to change.
rhalbersma commentedon Oct 30, 2020
Yes, so people who really like the hash codes in their publication-ready plots, need to change their code to
repr(p). So it's not backward compatible.ENH: print(p) returns an empty string (no hash)
ENH: print(p) returns an empty string (no hash)