Hi, it seems importing the GIS breaks a former
from time import time import as demonstrated in the following example.
Switching the imports works, but it's not intuitive, and neither very PEP 8.
import timescattered around in the __init__.py file. Wouldn't it be better to narrow the import to a
from time import sleepin the imports at top of the file?
Guess I could, but the take from What is the preferred way to report found bugs in the Python API? and https://community.esri.com/thread/196929-geonet-or-github-for-technical-questions-about-api was that GeoNet was the preferred channel for this kind of reports.
I think this is more of an ArcPy issue than an ArcGIS API for Python issue, but it becomes an issue for the latter when the former is imported. If you import ArcPy first (not suggesting it as a workflow/workaround, just for testing), then importing from arcgis.gis doesn't clobber your time import.
(arcgis-py3) C:\Users\user\AppData\Local\ESRI\conda\envs\arcgis-py3>python Python 3.6.5 |Anaconda, Inc.| (default, Mar 29 2018, 13:32:41) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from time import time >>> type(time) <class 'builtin_function_or_method'> >>> import arcpy >>> type(time) <class 'module'> >>> from time import time >>> type(time) <class 'builtin_function_or_method'> >>> from arcgis.gis import GIS >>> type(time) <class 'builtin_function_or_method'> >>>
Unfortunately, importing from datetime and time can be tricky since the modules contain classes with the exact same names. For that reason, I just import the time module since time() doesn't save much over time.time(). For datetime, I usually do from datetime import datetime as dt.
It would be great if we had a time.Time class instead of a time.time class, and a datetime.Datetime class instead of a datetime.datetime, but I don't know the full history of why those two modules ended up the way they did.
Good point, guess it explains the difference between cloned Pro-environments and environments built in Conda.
And yes, switching the imports works, but it is neither intuitive nor good style as mentioned in the original post.