Computers: A Fun Fish Function

I do a lot of Python scripting for scientific "computing" and data analysis, and I like to use the built-in, offline, documentation of numpy and python as much as possible. I find it really helpful!

Since I don't use an IDE, I have to use a Python REPL to type help(numpy.nditer) or whatever. But usually I have a script running, so I need to open a new terminal, open a REPL, import the module, and then type the help command.

To speed this up, I wrote the following fish function:


function py_help --description "import module and look up function"
    if test (count $argv) -eq 1
        python -c "import $argv[1]; help($argv[1])"
    else
        python -c "import $argv[1]; help($argv[1].$argv[2])"
    end
end

It invokes python with a supplied command which imports the first argument and asks for help, using the second argument to specify which attribute. The if statement is because I don't need the attribute all the time, like with pdb.

You could write a similar script in bash or zsh or whatever, but I use fish because it is easy and also cute.