Select to view content in your preferred language

Use of f-strings in GP Tools Share As WebTool

551
1
05-16-2024 01:34 AM
Status: Closed
Labels (1)
tempMarcHoogerwerf_EsriNL
Occasional Contributor

Enable the use of Python f-strings to assemble paths to data sources.

Currently if I use Python f-strings to assemble paths to data sources, the GP Tool runs fine, but when publishing this GP tool through Share as WebTool, the Analyze process will trow en error:

 

 

00068: Result <value> contains broken project data source: <value>

 

For example:

 

folder = "c:/temp"
fdgb = "test.gdb"
fc_name = "my_example"

ds = f"{folder}/{fgdb}/{fc_name}"
if arcpy.Exists(ds):
    arcpy.management.Delete(ds)

 

Currently, as suggested in Article ID: 000022882, a work-around could be to replace the / in the string literal with ? and then use .replace('?',"/)" to fool the Analyze process.

Instead of relying on this work-around,  it would be much cleaner to have the f-strings properly supported when using the Share As WebTool, as they are the preferred way of string formatting in current Python 3.x versions

Tags (2)
1 Comment
DrewFlater
Status changed to: Closed

This was more of a defect, so I am closing it as such. Pro 3.5 has improved parsing of Python scripts for swizzling data path strings. The f string pattern shown above will no longer raise an error. The folder variable will be updated by the consolidation swizzling, and the full contents of the c:\temp directory would be uploaded to the server during publishing of the web tool.