Select to view content in your preferred language

sys.argv are empty in python script after calculating field with Python syntax

3070
3
08-21-2012 11:20 AM
JasonMiller
Deactivated User
I am having a problem that I'm wondering if anyone else can duplicate (with the attached file)

I create a python script (attached is one that takes 2 shapefiles and combines them into one... )  I put code in to detect if a certain command line argument is provided ( /notify )  and if so, it plays a sound to indicate that it's done.  I then call the python script from a batch file with the  /notify  argument.  Here is the problem... in my python script I have several CalculateField calls that use PYTHON_9.3 syntax, after the first CalculateField method is called, the sys.argv "disappear" and are no longer accessible.  A bug possibly???

Attached is a zip file that I would like several people to test and see if they get the same results... directions...

1. Unzip the attachment to any directory
2. Run the .bat file.  It calls the python script with the /notify argument
3. Observe the output.  The python script prints out the sys.argv  several times and the 3rd time they are blank...

Any input is greatly appreciated...
Jason
Tags (2)
0 Kudos
3 Replies
JustinShepard
Deactivated User
I can't download your sample right now but what happens if you set a variable to the sys.argv rather than holding onto it?
0 Kudos
StephanieWendel
Esri Contributor
The behavior you describe is similar to what happened in this bug:  NIM079109 When using a combination of arcpy.CalculateField_management, Python parsers, and sys.argv[...

This was rejected as designed saying to use os.getcwd() instead of sys.argv[0] as it is more reliable. I would try this method instead.
0 Kudos
JasonMiller
Deactivated User
To Justin:
Brilliant idea... that works...

It would still be interesting to know if this problem exists for other users or not... so for now I will leave the post as "un-answered", however credit goes to you for providing a solution...


To Stephanie:
I cannot view the link given, however your argument is invalid.  I am trying to access sys.argv[1], not sys.argv[0]


Jason
0 Kudos