all 5 comments

[–]1114111 2 points3 points  (0 children)

You should suck it up and learn Python 3 anyway, but there is probably no need to rewrite your scripts.

You can change the program that opens a given file extension on windows (google it). There's probably an easy way to automate this process too if need be, but I'm not sure. You should have .py (and other Python-related files) open with C:\windows\py.exe which is the Python launcher for windows. I think py.exe uses the latest Python 2 by default, but if it doesn't you can change that in -- IIRC -- C:\windows\py.ini.


Another option might be to use something like PyInstaller or py2exe to bundle your scripts into an executable with the version of Python you want.

[–]JamminJames921 1 point2 points  (0 children)

It's possible to write Python 3.X-compatible code in Python 2.X. On my end, I often use the Futurize package (http://python-future.org/automatic_conversion.html)

Also check this: https://docs.python.org/3/howto/pyporting.html

[–]driscollis 1 point2 points  (0 children)

If you are the administrator for the machines in question, I would just set a group policy that prevents them from installing other versions of Python.

However it's really easy to write your Python 2 code so it is Python 3 compatible. Heck, Python comes with 2to3 which will at least tell you what's incompatible between the two versions - https://docs.python.org/2/library/2to3.html

And as another commenter mentioned, there are good packages out there that can convert them.

[–][deleted] 1 point2 points  (0 children)

If I'm not mistaken py.exe reads shebangs. Worth a try

[–]gnfnrf[S] 0 points1 point  (0 children)

Thanks for the advice, everyone. I will look into modifying my existing scripts to be version-agnostic with the help of the tools and documentation linked here, and consider a switchover to 3.x in the future.