This is a VERY general question, but it would be very helpful to get this figured out. Sometimes, when I enter "item.properties" I get nice list of properties. And sometimes, I get nothing. 'check_item' below is a feature service view. I wanted to know which properties I have access to and the 'properties' attribute says 'None.'
print(check_item.properties)
None
There are many I know of: 'title' 'shared_with' 'snippet' etc... How does one acquire a list of the available properties of an item? jupyter does not seem to have autofill.
Thank you,
R
Solved! Go to Solution.
The documentation states that Item objects have a base of a dictionary.
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## print each property name
for p in item.keys():
print(p)
Want to see the keys and values printed neatly...
from arcgis.gis import GIS
import json
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## print property name : value
print(json.dumps(item, indent=4))
As mention by @DavidSolari, you can use dir(), this will return beyond the item dictionary properties and include the class properties and methods amongst others.
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## dir() will return the dictionary properties, class properties and methods, dunder methods and properties
print(dir(item))
When in doubt, dir is your friend!
The documentation states that Item objects have a base of a dictionary.
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## print each property name
for p in item.keys():
print(p)
Want to see the keys and values printed neatly...
from arcgis.gis import GIS
import json
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## print property name : value
print(json.dumps(item, indent=4))
As mention by @DavidSolari, you can use dir(), this will return beyond the item dictionary properties and include the class properties and methods amongst others.
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## dir() will return the dictionary properties, class properties and methods, dunder methods and properties
print(dir(item))
Thank you. I appreciate it. I'm going to fess up here. I find the documentation extremely difficult to understand. I basically just hunt and use trial and error until something works. It's designed for coders of course and that's understandable. I wonder if there's a way people like me who work with notebooks and usually can get them to work to get background that would make the documentation more readable? It seems like a lot of scanning is required, few links...
This works perfectly (Thank you!):
from arcgis.gis import GIS
## access ArcGIS Online
agol = GIS("home")
## get the Feature Service as an Item object
item = agol.content.get("ITEM_ID")
## print each property name
for p in item.keys():
print(p)
This, using the same item id, does not:
from arcgis.gis import GIS import json ## access ArcGIS Online agol = GIS("home") ## get the Feature Service as an Item object item = agol.content.get("ITEM_ID") ## print property name : value print(json.dumps(item, indent=4))
for 'item' I entered a feature service view's item id.