AnsweredAssumed Answered

GetParameterAsText using 'r' like raw strings?

Question asked by recurvata on Apr 5, 2012
Latest reply on Jul 6, 2018 by lpinner
I've looked everywhere I can think of for a solution, or at least similar problem, to this but can't find one.

The script gets a user entered value via GetParameterAsText(0).

The value normally contains '-' characters, a typical one taking the form Z-FY-12-34, for example. When I try to set a text field to this value, CalculateField apparently treats the value as a number, subtracting the numbers and discarding the letters; the value then gets set to something like -46. I'm not sure it actually subtracts, but it always returns a - followed by a number. Whenever I check the value in the script, it looks correct.

I'm guessing that maybe this is related to using r to accept a raw string, but I don't know how to do that with GetParameter..., and maybe that's not the actual problem anyway. Any ideas on what the cause is and how to fix it? Thanks.

case_number = arcpy.GetParameterAsText(0)   # user enters Z-FY-12-34 . . .  fc = "Cases"     fld = "Case_"      arcpy.AddMessage("Adding Case number " + case_number + " added.")   # case_number = Z-FY-12-34      try:         arcpy.CalculateField_management(fc, fld, case_number)                  # field value set at -124 or some other number         arcpy.AddMessage("Case number " + case_number + " added.")   # case_number = Z-FY-12-34     except Exception as e:         arcpy.AddError("Error setting Case_ field value to case number. \n" + e.message)