1

In the below image, I am trying calculate my XY_LINK field to return the values from Point_X and Point_Y field.

Example of final result: {2474785.499662}{376075.063004}

enter image description here

My code is as follows:

Output(!POINT_X!, !POINT_Y!)

def Output(POINT_X, POINT_Y):
    FPX = round(float(X, 4)
    FPY = round(float(Y, 4)
    return "{%(FX)012.4f}{%(FY)012.4f}" % {'FX': FPX, 'FY': FPY}

The error I am receiving is as follows. (I am brand new to Python)

Failed to execute. Parameters are not valid. Error 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 3)

I don't understand why the error is being returned on Line 3 and not like 2 also since they are the same with the exception of the X and the Y.

  • You defined your variables as POINT_X and POINT_Y, but you use in the function X and Y It needs to be round(float(POINT_X,4)). It is also not clear what you want to do with your string (012.4f ?). – Matte Jun 6 '16 at 19:54
  • I actually got the code from someone who was trying to help me earlier so I'm not really sure what that 012.4f is for. The extra parenthesis causes an error that Float() takes at most one argument (2 given) I just want to combine the X and Y fields into the XY link field. Your suggestion did not work either. – hherrmann Jun 6 '16 at 20:04
  • Search string format in python and try again. I also hope that 1st line shown is sitting in a separate box outside expression – FelixIP Jun 6 '16 at 20:18
1

You defined your variables as POINT_X and POINT_Y, but you use in the function X and Y. Then i also would go for an easier approach and not the old string formatting method, that is harder to read. In the code block you can put the following that is more logical (in my opinion):

def Output(POINT_X,POINT_Y): return '{'+str(round(float(POINT_X),4))+'}'+'{'+str(round(float(POINT_Y),4))+'}'

  • That worked! I don't understand how but thank you! – hherrmann Jun 6 '16 at 20:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.