Hi guys, I am trying to calculate a field to read 2" HDPE in every row
#Calculate field Conduit feature class Underground arcpy.CalculateField_management("Underground.dbf", "Conduit", '"2in HDPE"', "PYTHON3")
With this I can get every row to read 2in HDPE but everytime I try to insert " instead of in I get an error. Could you guys help me please!
Thanks!
-Jim Noble
Jim,
Try this:
arcpy.CalculateField_management("Underground.dbf", "Conduit",
'"2\" HDPE"', "PYTHON3")
You need a forward back slash (\) before the parentheses ("). Otherwise, the Python interpreter will think you are trying to close the string.
Best,
Josh
Forward slash? I think "\" is commonly called backslash.
Even with escaping the double quotes, the string still needs to be single quoted and not double quoted.
"'2\" HDPE'"
Thanks Joshua, your fix worked perfectly.
Just got back from an ESRI user seminar: at pro 2.5 there finally is Find and Replace functionality!
Personally, I shy away from any special characters in database field values; notice how you need to escape them to get them in there. 'nuff said.....
not quite the same... but "unicode" is quite a large world to fully explore.
dq = u"\u201D"
f"quoting{dq}"
'quoting”'
"quoting{}".format(dq)
'quoting”'
s = '12in pipe'
s = s.replace('in','\"')
print(s)
12" pipe
Hi Joe, while your fix didn't pop any errors, it didn't actually fix the problem. Maybe I was using it wrong. This is what I put in.
#Calculate field Conduit feature class Underground arcpy.CalculateField_management("Underground.dbf", "Conduit", '"2in HDPE"', "PYTHON3") #Set in name replace with quotation s = '2in HDPE' s = s.replace('in','\"')
Jim, using Joe's code didn't change anything because you ran it after Calculate Field. The way the code is written now, you are using Calculate Field to update a table and then changing a string within Python but that change is never making it back into a data set.
I see. Thanks for the explanation!