[Python-ideas] cli tool to print value, similar to pydoc
Thomas Gläßle
t_glaessle at gmx.de
Sun Apr 7 07:42:46 EDT 2019
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 963 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20190407/9ba58eb5/attachment-0001.sig>
More information about the Python-ideas
mailing list