1# A-1class definitions for FP trees2 classTreeNode:3 def _init_ (self,namevalue,numoccur,parentnode):4Self.name=Namevalue; # node's name5Self.count=Numoccur; # Number of occurrences6self.nodelink=None; # links to similar element items7Self.parent=parentnode; # parent Node8self.children={}; # child Nodes9 def Inc (Self,numcoour): # Method Inc () adds a given value to the count variableTenself.count+=numoccur; OneDef disp (self,ind=1): # Method Disp () to display the tree as text APrint' '*ind,self.name,' ', self.count); - forChildinchself.children.values (): -Child.disp (ind+1);
The above defines a class TreeNode method with _init_ (Self,namevalue,numoccur,parentnode), Inc. (Self,numcoour), disp (self,ind=1);
Initialize error mode:
1>>>2>>>Importfpgrowth;3>>> Rootnode=treenode ('Pyramid', 9, None);4 Traceback (most recent):5File"<pyshell#5>", Line 1,inch<module>6Rootnode=fpgrowth.treenode ('Pyramid', 9, None);7Typeerror:object () takes no parameters
The right way:
1 2 Import fpgrowth; 3 >>> Os=treenode (); 4 >>> rootnode=os._init_ (' pyramid ', 9,none) 5 >>> rootnode6 >>> type (rootnode)7 <class 'nonetype'>8
How do I initialize a class class in Python?