On Apr 1, 2020, at 23:47, Abdur-Rahmaan Janhangeer <arj.pyt...@gmail.com> wrote:
> 
> Let's say i have a package.
> 
> >>> import package
> >>> package
> <module 'package' from '<path>'>
> 
> would it be nice to be able to change the repr of the package to 
> 
> >>> package
> package something
>     some message
>     ....

I don’t think so. Objects in Python have a str for “human readers” and a repr 
that’s more useful for debugging. The repr is nearly always either an 
expression you can copy and paste to create an equivalent object, or something 
in angle brackets that crams in the type and other useful-for-debugging 
information. And it nearly always has no newlines (even a string with newlines 
or a tuple of strings with newlines or a file whose path has newlines, the 
newlines get escapes), so you can log messages with reprs and know you’ll get 
one message per line.in the log output. Why should modules break all of that, 
and be different from strings, tuples, functions, classes, etc.?

The str, which you get from print(package), might be a different story. If 
there’s a representation of a module that’s more useful to end users than the 
repr, even if it’s not as good for debugging, the str should use that 
representation. But is there? What would the message be? How would the module 
specify it? And how it would be useful for the end user to see that message?

There’s a third thing that all types have besides repr and str, the docstring, 
which you get from help(package). Unlike the repr and str, the docstring is 
generally a constant, so it has no way of including runtime information, but 
that’s usually not a problem, and I don’t think it is for your use here. And it 
seems like the docstring might already be what you want. If so, I think it’s 
perfect for help(package) but would be wrong for print(package).

I may be misinterpreting something about the goals of your proposal. If so, I 
apologize—but it would really help if you give a real example: some known 
module, what message you think it should include in its repr, where you plan to 
print out that repr, how you’d like to specify it within the module source, etc.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/5F4XOKL3ENTX2HM3WH6BX7VCXWKWADQS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to