Hi,

what do you think about adding a tool to print a specified object,
similar to pydoc shows its help?

I regularly find myself checking the contents of variables to get a
quick grasp on what the value looks like during development, and then
type something like this:

    python -c 'import os; print(os.pathsep)'

    # or even
    python
    >>> import os
    >>> os.pathsep

other examples may be MODULE.__version__, sys.path, or sys.platform, but
really this happens a lot for a lot of different things.

It would be nice to just type, e.g. any of:

    pyval os.pathsep
    python -m pprint os.pathsep
    python -p os.pathsep
    pydoc --value os.pathsep

There is already a tool like this on PyPI [1] (sadly py2 only atm), but
if you agree that this is a common pattern, I believe it would be a lot
more useful to have it in the stdlib.

[1] https://pypi.org/project/pyeval/


Additional considerations:

It might be useful to add an option to pass a format specification,
which would then do the equivalent of:

    print(format(value, spec))

Note that [1] is even more powerful, because it can directly evaluate
expressions, e.g.:

    pyeval 'math.sin(math.pi/5)'

This can be really useful at times, but maybe the base version would be
enough for a first step.

What do you think?

Best, Thomas

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to