[BangPypers] Favorite tips/techniques

Vineet Naik naikvin at gmail.com
Tue Sep 10 13:02:11 CEST 2013


On Tue, Sep 10, 2013 at 4:21 PM, Noufal Ibrahim <noufal at nibrahim.net.in>wrote:

> 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.
>

If you are using jedi[1] with auto-complete in emacs, C-. takes you to the
definition by opening the module file in a write protected buffer. I use
jedi mainly for this feature and inline documentation popout rather than
for autocomplete :-)

[1] https://github.com/tkf/emacs-jedi


>
>
> [...]
>
>
> --
> Cordially,
> Noufal
> http://nibrahim.net.in
> _______________________________________________
> BangPypers mailing list
> BangPypers at python.org
> https://mail.python.org/mailman/listinfo/bangpypers
>



-- 
Vineet Naik


More information about the BangPypers mailing list