Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"AttributeError: 'NoneType' object has no attribute" when creating class [closed]

I have defined a simple class but recieve the error AttributeError: 'NoneType' object has no attribute 'bar' when trying to use it. What am I doing wrong?

def Foo():
    a = 0
    def bar(self):
        return self.a

f = Foo()
f.bar() # error
like image 265
PickleProgrammer Avatar asked Jun 05 '26 21:06

PickleProgrammer


1 Answers

This is the syntax to define a function

def Foo():

to define a class you'd say

class Foo:
like image 173
Cory Kramer Avatar answered Jun 07 '26 10:06

Cory Kramer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!