Thanks for the snippet,

Was wondering if given as a package option,
we might display the module's help info.

Out of curiosity how did you learn about sys.displayhook?

Thanks.

Kind Regards,

Abdur-Rahmaan Janhangeer
compileralchemy.com <https://www.compileralchemy.com> | github
<https://github.com/Abdur-rahmaanJ/>
Mauritius


On Thu, Apr 2, 2020 at 11:07 AM Steven D'Aprano <st...@pearwood.info> wrote:

> 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-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/RBOUOF6XETNU7XP4ZNAG2YRTVFNYDRW5/
> Code of Conduct: http://python.org/psf/codeofconduct/
>
_______________________________________________
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/HSQR43GXIR4TNONPBF2ACMSBMC6SROQA/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to