maintain 2 versions of python on my computer
Mike
mike at mhuffman.com
Sat Jan 16 12:32:18 EST 2010
> On unix you would start the file with a "hashbang" e.g.
>
> #!/usr/bin/python3
>
> Fraid I don't know if that works on XP though.
>
> Roger.
It does not; Windows associates applications with file extensions.
However, I have used something like this to get something like the
Unix shebang behavior:
@echo off
rem = """ ver26.bat: Python 2.6
C:\Python26\python -x %~f0 %*
goto END
rem """
# ver26.py wrapped in ver26.bat to mimic Unix #! behavior
import sys
print sys.version
rem = """
:END
pause
rem """
@echo off
rem = """ ver31.bat: Python 3.1
D:\Python31\python -x %~f0 %*
goto END
rem """
# ver31.py wrapped in ver31.bat to mimic Unix #! behavior
import sys
print(sys.version)
rem = """
:END
pause
rem """
I cannot remember where I first saw this, and don't think I have ever
seen it since. It seems like a bit of a hack, but I use it from time
to time when I cannot rely on Windows file associations. Perl has
a much cleaner way to accomplish the same thing for Windows (see the
pl2bat.bat script that ships with
Perl Windows distributions).
Mike
More information about the Python-list
mailing list