I'm working on a Python script that is heavily utilizing Network Analyst tools. I understand that dot notation is used to call methods from a class, but don't really get why/how ArcPy functions appear to be callable with different syntaxes. Example:
import arcpy
from arcpy import na
# what is the difference between this:
arcpy.na.CopyTraversedSourceFeatures(routeLyr, gdb, edges, junctions, turns)
#and this:
arcpy.CopyTraversedSourceFeatures_na(routeLyr, gdb, edges, junctions, turns)
Both syntaxes appear to behave the same when running from the Python window in an ArcMap session, but will these behave differently when running from a different environment, such as a script tool or a batch file run in Task Scheduler?
1 Answer 1
Both are just different names for the same thing. You can see this by using the is
operator:
arcpy.na.CopyTraversedSourceFeatures is arcpy.CopyTraversedSourceFeatures_na
will return:
True
Which tells you that both of these names point to the same object.
Your best course of action is to pick one way of doing it in your scripts and stick with it. Just be consistent.
Explore related questions
See similar questions with these tags.