On Thu, Apr 02, 2020 at 10:44:02AM +0400, Abdur-Rahmaan Janhangeer 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 know, would it be nice? For what purpose? What will the message
be? Where does the message come from?
The Python shell just prints the repr() of the object. If you want it to
print something different, you can install a custom display hook:
py> from types import ModuleType
py> def thingy(obj):
... if isinstance(obj, ModuleType):
... print("module %s is amazing!" % obj.__name__)
... print("...and Python is great!")
... else:
... print(repr(obj))
...
py> sys.displayhook = thingy
py> 'hello'
'hello'
py> math
module math is amazing!
...and Python is great!
--
Steven
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-leave@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/RBOUOF6XETNU7XP4ZNAG2YRTVFNYDRW5/
Code of Conduct: http://python.org/psf/codeofconduct/