In Linux and OSX you can create a bash script to do this for you. For example:

#!/bin/sh
python /path/to/script.py $@

As for Windows, I think you can do something similar, I don't know batch very well.

Alex

On 04/08/2011 02:02 PM, James Fort wrote:

Hello SeaPIG,

I wonder if anyone knows how to address the following issue.I looked in a book and Googled for a while and couldn't find what I'm looking for.

I want to have a directory or set of directories that contain Python scripts which I can execute from anywhere in my file system.Right now, I'm concerned with Windows XP, but I may want to do the same in Mac OSX and Linux in the future.Essentially, I want to by able to type:

currentDir>>>python script.py arg1 arg2

Where arg1 and arg2 might be files in the current directory that act as inputs to the script and script.py is a script that resides in another directory.

Here are some ideas I considered:

    * Setting the PYTHONPATH variable to include a directory where
      script.py is stored.This did not work.It seems to only work for
      importing modules once the Python interpreter is already invoked.
    * I read online and in a book that you can set "#!/usr/bin/python"
      as the first line in a script, assuming that this is the full
      path to the interpreter, put the script in /usr/bin or any other
      directory to which PATH points, and run the script using
      ">>>script.py".I read that this is only an option in Unix,
      however, and it doesn't allow me to specify the version of
      Python I want to use as would be possible if I prefixed the
      script submission command with ">>>python26 script.py".This also
      precludes me from using ">>>run script.py" from within Ipython.

Does anyone know how to handle this?I noticed that I run the same script by copying the script into the directories in which I want to run it, but when I make revisions to the script, I have different versions sitting in different directories, which is becoming very difficult to manage.

Thanks,

James

Reply via email to