0

I want to call a dict through a recursive function.
I want to print Goal.
However, I get the following error:(

Variable
asdf =  {'aws_iam_policy': {'vpc_flow_log_cloudwatch': {'__end_line__': 94,
                                                 '__start_line__': 88,
                                                 'count': ['${local.create_flow_log_cloudwatch_iam_role '
                                                           '? 1 : 0}'],
                                                 'name_prefix': ['vpc-flow-log-to-cloudwatch-'],
                                                 'policy': ['${data.aws_iam_policy_document.vpc_flow_log_cloudwatch[0].json}'],
                                                 'tags': ['${merge(var.tags,var.vpc_flow_log_tags)}']}}}
Code
def test(test:dict):
    for key, values in test.items():
        if type(values) is dict:
            test(values)                        # Error TypeError: 'dict' object is not callable
        else :
            print("Goal")
test(asdf)                          
Output
Traceback (most recent call last):
  File "/InitCloud/scan/scan/cand0.py", line 49, in <module>
    test(asdf)                          
  File "/InitCloud/scan/scan/cand0.py", line 45, in test
    test(values)                        # Error TypeError: 'dict' object is not callable
TypeError: 'dict' object is not callable

1 Answer 1

1

You have not clarified what you want, but your recursive function is wrong. It must be like this.

def test(a_dic):
    for key, values in a_dic.items():
        if type(values) is dict:
            test(values)
        else: print('Goal')
            
test(asdf)
Sign up to request clarification or add additional context in comments.

1 Comment

I wanted this thank you! Let's take a look and see. thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.