Question

bit of background. I work for a VFX studio and we have in the past had to alter .py files for other programs just using notepad or notepad++, but no one ever actually used python.

So I have been rolling out python automation scripts now and they're working great, except one problem. Any machine who previously had python scripts associated with something other then python fail.

The script is called with an argument:

myScript.py <argument>

then I use:

print sys.argv
versionName = sys.argv[1]

This works great on all machines that never had python files associated with anything, however machines that had python previously associated with another application fail it won't read the argument and i get a list index out or range error. The print line shows it is not recieving the input properly either.

Any thoughts on how to fix this?

Edit: Script returns this when run:

z:\pythonScripts>Make_version_1.py test
['Z:\\pythonscripts\\Make_Version_1.py']
Traceback (most recent call last):
    File "Z:\PythonScripts\Make_version_1.py", line 20, in <module>
        versionName = sys.argv[1]
IndexError: list Out of range

This error is not returned form the majority of the machines in the office .. just ones where .py files had been associated with another program before python 2.7.6 was installed, so i know the code works.

Was it helpful?

Solution 2

Just wanted to share that i fixed the issue. Apparently preassociating a .py file breaks the setup of the windows path during installation. On my main machine i didn't need to adjust it, but i now have on all machines by adding ;c:\python27;c:\python27\scripts to the environment variable. Now it works fine

OTHER TIPS

You need to tell Windows that you want to pass arguments to python. Open a command prompt, and do this:

assoc .py=PythonFile
ftype PythonFile=python.exe %1 %*
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top