1

I have the following problem in Python:

class MyClass:

    def __init__(self, number):
        self.variable = number

    def function(self, argument=(self.variable)):
        some_code()

It gives me the following error:

NameError: name 'self' is not defined

I need the instance variable to act as the default value of the argument in the function. Am I doing it right in passing the instance variable like that or am I missing something?

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • @NayantaraJeyaraj Indentation in Python matters. If you remove the indentation, you will get an error saying "IndentationError: unexpected indent", which is clearly not relevant to this question. – Donald Duck May 31 '18 at 11:01

0 Answers0