Python development tools

Tim Chase python.list at thechases.com
Sun Jun 23 20:54:26 EDT 2013


On 2013-06-23 20:22, Roy Smith wrote:
> In article <ba5cbbcc-ff44-467d-91b6-108573da5dda at googlegroups.com>,
>  rurpy at yahoo.com wrote:
>> Other things like finding all uses of various objects/functions
>> etc would also be useful now and then but I suppose that is a 
>> common IDE capability?
> 
> $ find . -name '*.py' | xargs grep my_function_name
> 
> seems to work for me.  I suppose a language-aware grep would be
> even better, because then it wouldn't find my_function_name when
> it's embedded in docstrings, comments, and the like.
> 
> On the other hand, you probably want to find those too.

Most good editors (and IDEs?) should handle this as well.  I can
speak for Vim where I could do something like[1]

  sh$ vim *.py
  :set hidden
  :argdo %s/\<my_function_name\>/new_func_name/gc

then evaluate the results, optionally issuing ":wall" to write all the
changes.

Alternatively, if you just want to find all the pattern-matches and
view them, you can use

  :vimgrep /\<my_function_name\>/ **/*.py

and then navigate them either using the quick-fix window:

  :copen

or go forward/backwards in the quick-fix list with[2]

  :cnext
  :cprevious

I'd wager money that Emacs allows you to do something similar, but
I'd have to let an Emacs-user step in to answer that.  YMMV with
other editors.  Is this a "refactoring" tool, or just a valuable
tool, regardless of how it's used for refactoring :-)

-tkc


[1]
The ":set hidden" tells Vim that it's okay to leave a buffer without
writing it, but still remember the changes made.  Many folks have
this in their vimrc configuration.  If you know you want to do it
everywhere, you can avoid the "c" flag to ask for confirmation.

[2]
These can be abbreviated as just ":cn" and ":cp"






.



More information about the Python-list mailing list