How you use Python with ArcGIS Pro is different from other ArcGIS products, including ArcGIS Desktop, ArcGIS Server, and ArcGIS Engine.
The Analyze Tools For Pro tool can be used to highlight issues that would prevent Python code or Python-based geoprocessing tools from running. The Analyze Tools For Pro tool uses the Python 2to3 utility to report potential migration issues. The tool also identifies tools and functionality that have not migrated to ArcGIS Pro.
Changes to functionality in ArcPy
The majority of geoprocessing tools will continue to be available in ArcGIS Pro; however, some will not. Tools that are not included are those in the Coverage, Parcel Fabric, Schematics, and Tracking Analyst toolboxes. Additional tools in other toolboxes are also not available. For a full list, see the list of tools not supported in ArcGIS Pro.
The arcpy.mapping module has been removed and has been replaced with the arcpy.mp module in ArcGIS Pro to support mapping workflows in ArcGIS Pro.
The arcpy.na module also includes changes, many related to the change from arcpy.mapping to arcpy.mp.
Python 3
ArcGIS Pro uses Python 3. Python 3 is a popular programming language that is used in a variety of fields including data analysis, data science, quality assurance, and web and software development.
Héritage :
Earlier ArcGIS products, including ArcGIS Desktop, ArcGIS Server, and ArcGIS Engine use versions of Python 2. The Python 3 releases are a different line that are only partially compatible with Python 2. While fundamentally much of the language is the same, many details have changed, including how strings and dictionaries work and how the standard library is organized.
Converting an existing script use in ArcGIS Pro and Python 3
If you are doing a one-way conversion of code from Python 2 to Python 3, you can use the 2to3 command line utility to automate much of the process. This utility is available with both Python 2 and 3. It is important to note that the 2to3 utility, while an excellent tool, is not a complete solution (it is sometimes estimated as a 95 percent solution), and additional changes may be necessary. If you need to support both Python 2 and 3, see below for strategies.
Simpler Python scripts may not need changes at all and may run well without them.
The sections that follow describe some of the common differences between Python 2 and 3 that you are likely to encounter. In addition, one reference for porting to Python 3 and migration strategies is in Lennart Regebro's Porting to Python 3 at the http://python3porting.com/ website. It is possible to write scripts that run in both Python 2 and Python 3.
Standard library reorganization
Python 3 includes a reorganization of the standard library from Python 2. Most of these changes involve functionality that has been moved to a different location or is part of a module that has been renamed. To write code that works in both Python 2 and 3, these differences can be handled using flexible imports such as the following for modules such as urllib2:
try:
import urllib2 # Python 2
except ImportError:
import urllib.request as urllib2 # Python 3
print statement and function
One common cause of syntax errors in Python 2 is the conversion of the print statement to the print function. Fortunately, the print function has been backported to Python 2 and can be safely used in Python 2 and 3.
print('This will print safely in Python 2 and 3')
# print statements will only work in Python 2
# print 'Print statements will only print safely in Python 2'
__future__
At the top of your scripts, import the __future__ flags to make the Python 2 code subject to some of the new Python 3 rules. Once your scripts correctly parse with this line, you are well on your way to Python 3 compatibility.
from __future__ import print_function, unicode_literals, absolute_import
Dictionaries
Use dictionary.items() rather than dictionary.iteritems() when applicable. iteritems has been removed in Python 3, and items behaves like iteritems. The same applies to range and xrange: xrange has been removed from Python 3, and range now behaves like xrange.
Strings and encoding
In Python 3, anything in quotation marks is now implicitly a Unicode string. The byte array takes the place of the old str type. The unicode_literals import implicitly turns everything within quotation marks in Python 2 to Unicode.
Python 3 is stricter in how it handles character encoding. Explicitly save your scripts as UTF-8 if you haven't already. Add a coding line such as # coding: utf-8 at the top of your script so Python can identify that the script is in UTF-8.
io module
The io module was introduced in Python 2.6 and is included with Python 3. It provides a clean way of handling many input and output tasks in a text encoding-aware manner.
Unsupported data formats
Several data formats are not currently supported in ArcGIS Pro, including raster catalogs, geometric networks, schematic datasets, geodatabase servers, ArcMap document templates, ArcReader documents, graphs, tiled map packages, and personal geodatabases.
Vous avez un commentaire à formuler concernant cette rubrique ?