Analyze Tools for Pro - Python Scripts - Faulty Results

656
3
08-16-2018 12:47 PM
MichaelVolz
Esteemed Contributor

The below link is from ArcGIS Pro Help for migrating ArcMap based python scripts to Pro based python scripts as they run in different versions of python. 

http://pro.arcgis.com/en/pro-app/arcpy/get-started/python-migration-for-arcgis-pro.htm

There is a section on fixing print statements where parentheses were not required in ArcMap (python 2.x), but parentheses are required in Pro (python 3.x).

Near the top of the help page is a link for "Analyze Tools for Pro" that is in blue.  This link shows a python script that can be run in Pro called AnalyzeToolsForPro_management that will show you changes that need to be made to the script.

Below is a sample line from the txt file run on a python script.

Line 57:         print("This is the feature class " + fc) ->         print(("This is the feature class " + fc))

This print statement should be OK in either python 2.x or python 3.x, but the tool suggested adding an additional parentheses around the print statement.

As such, it seems like this tool is providing extraneous tips for upgrading python scripts that are misleading.

Tags (4)
0 Kudos
3 Replies
JoeBorgione
MVP Emeritus

As I understand it, in 3.x print() is method that takes arguments.  Since I'm at an impasse with v 2.2 I don't have access to Python3.x.  That said, my preference for any print statement is to use the format() method.  In your examples:

print 'This is the feature class {}'.format(fc)   #v 2.x

print('This is the feature class {}'.format(fc))  #v 3.x‍‍‍‍‍‍

For that matter, I prefer using the format() method for concatenating variables, strings, paths, etc:

a = 'This is variable'= '{} and this is another variable'.format(a)

dir = r'C:\temp\junk'
shape = 'joe.shp'

shape = '{}\{}'.format(dir,shape)

That should just about do it....
DanPatterson_Retired
MVP Emeritus

That is good Joe... works in python used with ArcGIS Pro (ie 3.6.x)

JoeBorgione
MVP Emeritus

Thanks... I mis-spoke.  I have Python 3.x with a Python window, just not Spyder.  Still waiting for an ESRI response to escalation...

That should just about do it....
0 Kudos