python - Why does PyDev require an object in place of Self when calling a class method? -


so new python, have seen recent popularity surround language decided give try , learn language. started developing simple arraylist using pycharm ide , had absolutely no issues @ all. have decided use pydev plugin eclipse new project binary search tree. problem running pydev when create class method self keyword being 1 of parameters, pydev seems require me place object in parameters of method called. example can seen below:

def addnode(self, data):     if(self.__root):         self.__addnode(self, self.__root, data)     else:         self.__root = treenode(data)      self.__size += 1     self.printtree(self, self.__root)      def __addnode(self, node, data):     if(data != none , node != none):         if(data <= node.getdata()):             if(node.getleftchild() == none):                 node.setleft(treenode(data))             else:                 self.__addnode(node.getleftchild, data)         else:             if(node.getrightchild() == none):                 node.setright(treenode(data))             else:                 self.__addnode(node.getrightchild(), data) 

if run following code:

bst = binarysearchtree bst.addnode(5) bst.addnode(4) bst.addnode(6) 

i following output:

traceback (most recent call last):   file "c:\users\------\workspace\binarysearchtree\main.py", line 9, in <module>     bst.addnode(5) typeerror: addnode() missing 1 required positional argument: 'data' 

but if run code instead:

bst = binarysearchtree bst.addnode(bst,5) bst.addnode(bst,4) bst.addnode(bst,6) 

i output looking for:

5  4 5  4 5 6  

so question why seem pydev requires object in place of self when calling class method when pycharm did not give me problem? have both ides using same interpreters.

you have not instantiated bst object. in python need call class:

bst = binarysearchtree() 

with code, calling methods on class itself, not on instance.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -