OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Python Passing values to functions from Nested Dictionary

  • Thread starter Thread starter user12336379
  • Start date Start date
U

user12336379

Guest
I'm new to python and playing with Nested dictionary called mydict{} located in a config.py file. i'm trying assign the key, value from nested dictionary using iteration and got the error

Code:
    myfunc(key, value['client_id'], value['client_secret'])
TypeError: string indices must be integers

Basically, i have a dictionary for each client and need to iterate for each.

Code:
def myfunc(myval1, myval2, myval3):
    config.ms_auth[TENANT] = myval1
    config.ms_auth[CLIENT_ID] = myval2
    config.ms_auth[CLIENT_SECRET] = myval3;
    <<< piece of logging functions goes here >>>
    with RequestManager(total_indicators, logger) as request_manager:
        logger.info("Start uploading Data")
        request_manager.upload_indicators(parsed_indicators)
        logger.info("Finished uploading indicators")
        
def main():
    tenants = json.loads(config.mydict)
    for key, value in tenants.items():
       myfunc(key, value['client_id'], value['client_secret'])

any ideas would be highly appreciated..
<p>I'm new to python and playing with Nested dictionary called mydict{} located in a config.py file. i'm trying assign the key, value from nested dictionary using iteration and got the error</p>
<pre><code> myfunc(key, value['client_id'], value['client_secret'])
TypeError: string indices must be integers
</code></pre>
<p>Basically, i have a dictionary for each client and need to iterate for each.</p>
<pre><code>def myfunc(myval1, myval2, myval3):
config.ms_auth[TENANT] = myval1
config.ms_auth[CLIENT_ID] = myval2
config.ms_auth[CLIENT_SECRET] = myval3;
<<< piece of logging functions goes here >>>
with RequestManager(total_indicators, logger) as request_manager:
logger.info("Start uploading Data")
request_manager.upload_indicators(parsed_indicators)
logger.info("Finished uploading indicators")

def main():
tenants = json.loads(config.mydict)
for key, value in tenants.items():
myfunc(key, value['client_id'], value['client_secret'])
</code></pre>
<p>any ideas would be highly appreciated..</p>
 

Online statistics

Members online
0
Guests online
5
Total visitors
5
Top