[BangPypers] Favorite tips/techniques
Noufal Ibrahim
noufal at nibrahim.net.in
Tue Sep 10 12:51:25 CEST 2013
Saju M <sajuptpm at gmail.com> writes:
> echo '{"name": "Bangpypers", "location": "Bangalore"}' | python -m json.tool
>
> In this command, what is this "json.tool" ?
>
> I could not find "tool" in dir(json)
>
>>>> import json
>>>> dir(json)
> ['JSONDecoder', 'JSONEncoder', '__all__', '__author__', '__builtins__',
> '__doc__', '__file__', '__name__', '__package__', '__path__',
> '__version__', '_default_decoder', '_default_encoder', 'decoder', 'dump',
> 'dumps', 'encoder', 'load', 'loads', 'scanner']
It needn't be.
>>> from json import tool
>>> tool.__file__
'/usr/lib/python2.7/json/tool.pyc'
>>>
json is a package and tool is one of the modules inside that.
To get to this, I have a little shell function that I stole from Anand that has
been super useful repeatedly.
epy () {
cmd="import $1 as a ; print a.__file__.endswith('.pyc') and a.__file__[:-1] or a.__file__"
file=$(/usr/bin/env python -c $cmd)
echo $file
emacsclient --no-wait $file
}
If you want to read the source for the json module, just do
$ epy json
and the json module is loaded into Emacs.
[...]
--
Cordially,
Noufal
http://nibrahim.net.in
More information about the BangPypers
mailing list