I am looking for help to write a loop a arcpy.CalculateField_maagement process where the User is asked with the 'raw_input', prior to the tool running "Do you need to change a field value(yes/no):",

if he types 'yes' into the input he is then prompted to enter a VB expression to replace a specific field like so "Replace([Column],"Value","newvalue"),

and the calculate field tool runs,if he types 'no' the script skips the Calculate field process and continues on to the next tool,

if the tool has run he is then asked, "Are there anymore fields you wish to update(Yes/no):" if he types 'yes' he is asked to enter another VB expression to replace a field value,

if he types 'no' the script skips the Calculate field process and continues on to the next tool.

I just need help writing the loop I have a giant python application that works but is not flexible in terms of allowing the user to edit data, and this will provide a lot of flexibility by allowing the user to choose if he wishes to edit a value or not.

here is a snippet of where I would like the Loop, I am currently also working on a way to Loop it and will edit the question with any progress I have made.

YesNo = raw_input(Do you need to change a field value(yes/no): ) #Ask User if there is a field value he wants to change, if his answer is yes then he is prompted to enter a SQL query that will run in the the Calculate Field Process, if he says no, the code skips the Calculate Field Process

VBexp = raw_input("Enter VB Expression to Update Field Names : ") #Enters a replace for his desired field expression 
arcpy.CalculateField_management("featureclass", "Column", VBexp , "VB", "")

Again = raw_input("Are there anymore fields you wish to update(Yes/no): ") #If the user specifies Yes he will be prompted to enter a new VB expression to change a different field & and if he says no the script will continue running

1 Answer 1


Alright great I managed to solve it, I hope this answer helps others.

while True:
 YesNo = raw_input("Do you need to change a field name (Yes/No): ")
except ValueError:
    print("Your Input is invalid")
if YesNo == "Yes":
    VB = raw_input("Enter VB Expression to change Your Field: ")  ##This is the expression I use: Replace([Column],"FieldtoChange","NewValue")
    arcpy.CalculateField_management("featureClass", "Columnwherenewvalueswillgo", VB , "VB", "")
  • 1
    Maybe you should validate the VB expression somehow? Or help the user by only having to specify column and new value in separate prompts, and then build the expression in the script?
    – Martin
    Jul 6, 2015 at 9:27
  • @Martin definitely going to add that functionality in, however right now its just a proof of concept. Thanks
    – user32496
    Jul 6, 2015 at 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.