0

When I call func1 from func2, I get an error. Why is this occurring and how to access the returned dictionary d in func1 from func2?

func1()
NameError: name 'func1' is not defined
class ABC():

    def func1(self, a):
         d = {}
         ###do something with a
         ###return ending dictionary d
         return d

    def func2(self):
         ###Retrieve returned dictionary d from func1 and use
         func1()
         d['key'] = value
2
  • class ABC: parthensis are not needed here Commented Jan 31, 2022 at 22:37
  • d = self.func1() calling a method and setting returned value to d (although you could use a completely different name here, e.g. result = self.func1()) Commented Jan 31, 2022 at 22:38

2 Answers 2

2

func1 and func2 are instance methods of ABC objects. You need to call them from the instance of such object. In your case, one such instance is self, first parameter of both functions. Thus, self.func1() will work.

Sign up to request clarification or add additional context in comments.

Comments

0

Use self.func1() to call the function inside your class.

Comments

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.