class foo:
#initially
def __init__(self):
self.nodes1=[]
self.nodes2=[]
self.edges=[]
def add_node(self,type,x,y):
if type==1:
self.nodes1.append(node1(x,y))
class node1:
def __init__(self,x,y): #Getting coordinates from outside while creating the class.
self.x=x
self.y=y
b_foo = foo
b_foo.add_node(b_foo,1,0,1)
I try to add an element to the class' array. This code gives an error like this:
AttributeError: type object 'bipartite' has no attribute 'nodes1'
Micha Wiedenmann
21.1k22 gold badges96 silver badges142 bronze badges
asked Sep 24, 2018 at 11:48
Sevval Kahraman
1,3113 gold badges15 silver badges47 bronze badges
-
1You are not creating the instance of class properly. Replace last second line with this b_foo = foo()vermanil– vermanil2018年09月24日 11:54:44 +00:00Commented Sep 24, 2018 at 11:54
1 Answer 1
You should create an instance of your class:
b_foo = foo() # creates a class instance
b_foo.add_node(1,0,1) # "self" is passed implicitly
answered Sep 24, 2018 at 11:51
Mike Scotty
10.8k5 gold badges42 silver badges52 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py