I am trying to add a file path field to a feature layer in an ArcPy notebook in ArcGIS Pro. I have a variable with the beginning of the path (the path to the folder) and an existing field with the file name. I have been looking at other questions on here and on ArcGIS help websites (e.g. How to use variable in expression in arcpy CalculateField tool?) but haven't found a way that works. If we pretend the folder is just my downloads folder, here is what I have tried as expressions within the arcpy.management.CalculateField command:
output_folder = "C:/Users/ellah/Downloads/"
expression = 'output_folder + !match.Filename!'
expression = str(output_folder) + '!match.Filename!'
expression = " ".join([str(i) for i in [output_folder, !match.Filename!] if i])
expression = "{}/{}".format(output_folder, !match.Filename!)
expression = "{0} + str(!match.Filename!)".format(output_folder)
... as well as some other small tweaks. I've tried using them as the expression as well as defining them as a function in the code block and running them that way. Everything works fine if I type out the actual folder path ('C:/Users/ellah/Downloads/') rather than calling the variable. I don't think it's an issue with the forward/backslashes or typos like a double slash.
Some errors I have gotten include:
ERROR 000539: Traceback (most recent call last): File "", line 1, in NameError: name 'output_folder' is not defined
ERROR 000539: File "", line 1 C:/Users/ellah/Downloads/out/u"1_in.png" ^ SyntaxError: invalid syntax



import os, os.path.join(output_folder,'!match.Filename!')?expressionneeds to end up as a string containing valid python code that can be parsed standalone. Tryexpression = "'{}' + '!match.Filename!'".format(output_folder)