0

I'am making my first steps with Python. I have written very simple program, yet it is not working. The error messege is: NameError: name 'fun' is not defined.
I'm using Spyder and Python 3.7.

class myClass(object):
    def __init__(self):
        self.a = fun()

    def fun(self):
        return 10

instance = myClass()
Patrick Haugh
  • 59,226
  • 13
  • 88
  • 96
Karol Borkowski
  • 532
  • 7
  • 19

1 Answers1

2

Instead of self.a=fun() use self.a=self.fun() then only it will become clear to interpreter as to which fun() you are referring to.

KTDLIN
  • 21
  • 3