Why is my class undefined?

Sayth Renshaw flebber.crue at gmail.com
Wed Aug 16 18:48:57 EDT 2017


Morning

I haven't ventured into classes much before. When trying to follow some examples and create my own classes in a jupyter notebook I receive an error that the class is undefined.

So I created for practise a frog class

class frog(object):
    
    def __init__(self, ftype, word):
        self.ftype = ftype
        self.word = ftype
        
    def jump(self):
        """
        Make frog jump
        """
        return "I am jumping"
    
    if __name__ == "__main__":
        tree_frog = frog("Tree Frog", "Ribbitt")
        print(frog.ftype)
        print(frog.word)
        

I receive this error

NameError                                 Traceback (most recent call last)
<ipython-input-1-609567219688> in <module>()
----> 1 class frog(object):
      2 
      3     def __init__(self, ftype, word):
      4         self.ftype = ftype
      5         self.word = ftype

<ipython-input-1-609567219688> in frog()
     12 
     13     if __name__ == "__main__":
---> 14         tree_frog = frog("Tree Frog", "Ribbitt")
     15         print(frog.ftype)
     16         print(frog.word)

NameError: name 'frog' is not defined

what exactly am I doing wrong?

Cheers

Sayth



More information about the Python-list mailing list