Raymond Hettinger wrote:
My understanding was that it wasn't about a full pathname to python, it was about searching sys.path for the darned script so us poor Windows guys don't have to change directories a million times a day (no aliases or shebangs for us either).
I have a big pile of batch files just to invoke timeit, texchecker, profile, etc. It bites the big one.
Sorry for the plug, but I hope you'll forgive it if it actually turns out to be
useful. You may want to have a look at ipython (http://ipython.scipy.org).
IPython has a 'magic' run command, which allows you to run any python script
from its command line:
In [1]: cat argv.py
#!/usr/bin/env python
import sys
print 'argv:',sys.argv
In [2]: run argv
argv: ['argv.py']
In its current form, it is just an execfile() on steroids. But it would be
trivial to add to it a -m option so that it would search in sys.path if nothing
in the current directory is found matching the given name.
Ipython also gives you aliases and 'bookmarks', a persistent list of directories
you can change to with a single 'cd' command:
############### 'screenshot'
In [1]: pdoc alias
Define an alias for a system command.
'@alias alias_name cmd' defines 'alias_name' as an alias for 'cmd'
Then, typing 'alias_name params' will execute the system command 'cmd
params' (from your underlying operating system).
[... snip. It's a long docstring]
In [6]: pdoc bookmark
Manage IPython's bookmark system.
@bookmark <name> - set bookmark to current dir
@bookmark <name> <dir> - set bookmark to <dir>
@bookmark -l - list all bookmarks
@bookmark -d <name> - remove bookmark
@bookmark -r - remove all bookmarks
You can later on access a bookmarked folder with:
@cd -b <name>
or simply '@cd <name>' if there is no directory called <name> AND
there is such a bookmark defined.
################ /screenshot
Using ipython's profile system (referred to earlier in this thread), you can use
it as a quasi-system shell. The provided 'pysh' profile loads all of your
$PATH (with proper extensions in Windows) as ipython aliases, and you can do
regular system things, but retaining python syntax. It has also a mechanism
for capturing shell output into python variables and expanding back to the
shell:
############### 'screenshot'
fperez@maqroll[~/test]|4> print 'Yes, this is still %s !' % 'Python'
Yes, this is still Python !
fperez@maqroll[~/test]|5> $$files=ls
fperez@maqroll[~/test]|6> type files
------------------------> type(files)
<6>