Re: Hi there! help?

0 views
Skip to first unread message

Jonathan Ellis

unread,
Aug 13, 2008, 5:39:46 PM8/13/08
to Bell, Kevin, utahp...@googlegroups.com
on unix, just set the "shebang" line --

#!/usr/bin/python2.4

on windows, I have no idea.

On Wed, Aug 13, 2008 at 11:07 AM, Bell, Kevin <kevin...@slcgov.com> wrote:
> I'm still blocked from IRC ; ( Can you help?
>
>
>
> How can I set the python executable when a script starts? I've got some
> scripts that need to run with 2.4 and new scripts that I want to run with
> 2.5…

Jason Corbett

unread,
Aug 13, 2008, 6:20:35 PM8/13/08
to utahp...@googlegroups.com, Bell, Kevin
There's no clean way like shebang on unix. Windows is using
associations to get python to execute the script, the same way that it
knows to use Word to open .doc files. You do have several options,
but none of them real clean. They all center around writing a wrapper
that looks at the first line to determine which version of python to
run. Here are some examples:

* Write a simple executable that is associated with python files in
windows, and have it inspect the first line to determine which version
of python to use
* for each script, write a bat or cmd file that you call instead of
the .py file that calls the right version of python

I'm sure there are more. I am most definitely NOT an expert on
windows, and couldn't tell you how to associate a .py file with an
executable, I'm sure it has something to do with the registry. I've
asked several other people in the office, and no one knows a good way
of doing this other than the examples I've included.

Jason Corbett

JORDAN GUNDERSON

unread,
Aug 13, 2008, 6:36:15 PM8/13/08
to utahp...@googlegroups.com
If you're using Windows and you plan on using the scripts a lot, you
could use something like py2exe to create python-independent
executables. Just a thought, but again, probably more effort than you
were looking for (even though it's pretty easy).

Jordy

stnc...@xmission.com

unread,
Aug 13, 2008, 7:07:04 PM8/13/08
to utahp...@googlegroups.com
I'd vote for Jason's option #2 (write a .bat or .cmd that wraps around
each script)

This doesn't really help with the problem of running some scripts with
2.4 and some with 2.5 -- You can use the FTYPE and ASSOC commands to
setup the registry file type magic, you can get help and an example
from 'ftype /?'

-Steve

Brandon Pedersen

unread,
Aug 14, 2008, 12:28:29 PM8/14/08
to utahp...@googlegroups.com
On Wed, Aug 13, 2008 at 4:20 PM, Jason Corbett <jasonc...@gmail.com> wrote:

I'm sure there are more. 

 
Why can't you just type 'python2.4 script.py'? Or do you not want to do it on the command line? If that is the case you could give a different extension to the 2.4 scripts like .py24 and then add an association in windows for that extension to call python2.4.

Jason Corbett

unread,
Aug 14, 2008, 5:22:46 PM8/14/08
to utahp...@googlegroups.com
That sounds like a much better solution.

Jason
Reply all
Reply to author
Forward
0 new messages