Hi Gents, Im starting in the python world. I recently wrote a code thanks to the apis and data available. The code I wrote is to get the organizations my company owns but im also adding things like printing the networks of each organization. Code is: import meraki, requests, time, apikey, json #Organizations print('********************************************************************') print('Listing Organizations xxxx') print('********************************************************************') url = "https://api.meraki.com/api/v1/organizations" payload={} headers = { 'X-Cisco-Meraki-API-Key': apikey.api_key} response = requests.request("GET", url, headers=headers, data=payload) allOrg = json.loads(response.text) for Organization in allOrg: print("Name: {} \t ID: {}".format(Organization["name"],Organization["id"])) print('********************************************************************') print('Listing Networks each Organization') print('********************************************************************') print('EU Networks') url = "https://api.meraki.com/api/v1/organizations/535660/networks" payload={} headers = {'X-Cisco-Meraki-API-Key': apikey.api_key} response = requests.request("GET", url, headers=headers, data=payload) networks = json.loads(response.text) for Networks in networks: print("Name: {} \t ID: {}".format(Networks["name"],Networks["id"])) print('********************************************************************') print('US Networks') url = "https://api.meraki.com/api/v1/organizations/419633/networks" payload={} headers = {'X-Cisco-Meraki-API-Key': apikey.api_key} response = requests.request("GET", url, headers=headers, data=payload) networks = json.loads(response.text) for Networks in networks: print("Name: {} \t ID: {}".format(Networks["name"],Networks["id"])) print('********************************************************************') print('APAC Networks') url = "https://api.meraki.com/api/v1/organizations/671036344478206491/networks" payload={} headers = {'X-Cisco-Meraki-API-Key': apikey.api_key} response = requests.request("GET", url, headers=headers, data=payload) networks = json.loads(response.text) for Networks in networks: print("Name: {} \t ID: {}".format(Networks["name"],Networks["id"])) print('********************************************************************') How I can build a loop to run the code but with one single loop instead of repeating the same code for each organization? This code works just fine, but im sure there must a be a way for me to simplify it and make it shorter in terms of the code Thanks in advance .
... View more