<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python List object to varaibles. in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372737#M9562</link>
    <description>&lt;P&gt;I guess my question is how to I access the Attribute Key and the Geometry Key and write their objects to variables.&lt;/P&gt;&lt;P&gt;This is what I am doing right now and ... querying a dataset and writing to json file and trying to read that and put into variables&amp;nbsp;&lt;/P&gt;&lt;P&gt;unless there is a better way?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    URL = targetURL + '/query'
    field = 'OBJECTID'
    whereclause = 'OBJECTID=2'
    PARAMS = {'token': portaltoken,'f': 'json', 'where': '{}'.format(whereclause), 'returnIdsOnly': False, 'returnCountOnly': False, 'returnGeometry': True,
                  'outFields': '*'}
    r = requests.post(url=URL, data=PARAMS)

    outjsonpath = outputVariable + "output.json"
    layer_data = r.json()
    layer_data_final = layer_data
    print('Writing JSON file...')
    with open(outjsonpath, 'w') as out_json_file:
        json.dump(layer_data_final, out_json_file)

    filetoImport = outjsonpath
    f = open(filetoImport)
    data = json.load(f)
    featureAddingAdd = data['features']

    print(featureAddingAdd)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 21 Jan 2024 17:45:04 GMT</pubDate>
    <dc:creator>kapalczynski</dc:creator>
    <dc:date>2024-01-21T17:45:04Z</dc:date>
    <item>
      <title>Python List object to varaibles.</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372736#M9561</link>
      <description>&lt;P&gt;I have this List object and need to massage it a couple ways...&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I would like it to read without the&amp;nbsp;{'attributes':&amp;nbsp; at the front and the trailing }&lt;/P&gt;&lt;P&gt;Like this:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{'OBJECTID': 2, 'PERMITTEE': None, 'ROUTE': None, 'GLOBALID': '{8BF971DC-473B-4C88-8007-363EDAE7D091}', 'RELGLOBALID': '{F06AD758-9BBB-4096-942D-484F9F2B0435}', 'INSPECTOR_NAME': None, 'PERMIT_INTERNAL_ID': None}, 'geometry': {'x': -77.393420655, 'y': 37.615990732}&lt;/LI-CODE&gt;&lt;P&gt;Second I would like to be able to set the OBJECTID, PERMITID, ROUTE etc to variables...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;{'attributes': {'OBJECTID': 2, 'PERMITTEE': None, 'ROUTE': None, 'GLOBALID': '{8BF971DC-473B-4C88-8007-363EDAE7D091}', 'RELGLOBALID': '{F06AD758-9BBB-4096-942D-484F9F2B0435}', 'INSPECTOR_NAME': None, 'PERMIT_INTERNAL_ID': None}, 'geometry': {'x': -77.393420655, 'y': 37.615990732}}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2024 17:24:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372736#M9561</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-01-21T17:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python List object to varaibles.</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372737#M9562</link>
      <description>&lt;P&gt;I guess my question is how to I access the Attribute Key and the Geometry Key and write their objects to variables.&lt;/P&gt;&lt;P&gt;This is what I am doing right now and ... querying a dataset and writing to json file and trying to read that and put into variables&amp;nbsp;&lt;/P&gt;&lt;P&gt;unless there is a better way?&lt;/P&gt;&lt;LI-CODE lang="c"&gt;    URL = targetURL + '/query'
    field = 'OBJECTID'
    whereclause = 'OBJECTID=2'
    PARAMS = {'token': portaltoken,'f': 'json', 'where': '{}'.format(whereclause), 'returnIdsOnly': False, 'returnCountOnly': False, 'returnGeometry': True,
                  'outFields': '*'}
    r = requests.post(url=URL, data=PARAMS)

    outjsonpath = outputVariable + "output.json"
    layer_data = r.json()
    layer_data_final = layer_data
    print('Writing JSON file...')
    with open(outjsonpath, 'w') as out_json_file:
        json.dump(layer_data_final, out_json_file)

    filetoImport = outjsonpath
    f = open(filetoImport)
    data = json.load(f)
    featureAddingAdd = data['features']

    print(featureAddingAdd)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2024 17:45:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372737#M9562</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-01-21T17:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Python List object to varaibles.</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372739#M9563</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dictionary... not list, check python documentation for more information.&amp;nbsp; Dictionaries have 'keys' and 'values' and they can be 'sliced'&lt;/P&gt;&lt;LI-CODE lang="python"&gt;d = {'attributes': {'OBJECTID': 2, 'PERMITTEE': None, 'ROUTE': None, 'GLOBALID': '{8BF971DC-473B-4C88-8007-363EDAE7D091}', 'RELGLOBALID': '{F06AD758-9BBB-4096-942D-484F9F2B0435}', 'INSPECTOR_NAME': None, 'PERMIT_INTERNAL_ID': None}, 'geometry': {'x': -77.393420655, 'y': 37.615990732}}

d.keys()
Out[2]: dict_keys(['attributes', 'geometry'])

d['attributes']  # -- slice by the key
 
{'OBJECTID': 2,
 'PERMITTEE': None,
 'ROUTE': None,
 'GLOBALID': '{8BF971DC-473B-4C88-8007-363EDAE7D091}',
 'RELGLOBALID': '{F06AD758-9BBB-4096-942D-484F9F2B0435}',
 'INSPECTOR_NAME': None,
 'PERMIT_INTERNAL_ID': None}

d['attributes']['GLOBALID']
'{8BF971DC-473B-4C88-8007-363EDAE7D091}'&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 21 Jan 2024 17:41:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372739#M9563</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-01-21T17:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: Python List object to varaibles.</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372742#M9564</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp; Cheers.... thanks for the correction and guidance... much appreciated.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2024 17:59:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-list-object-to-varaibles/m-p/1372742#M9564</guid>
      <dc:creator>kapalczynski</dc:creator>
      <dc:date>2024-01-21T17:59:41Z</dc:date>
    </item>
  </channel>
</rss>

