I've got this strange problem, I created an instance called structure, I made a function which return an object of this type. Just before returning, I print it, it gives me the right object. Now when I collect it in 'main' and print it, it becomes 'None'. If someone can give me advice, it will be very appreciated.

Regards
Faniry

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by faniryharijaona

Show me or it's not true.

-->

It is not really easy but this is the function

``````def locate(K,p):
"""
locate the point p in the structure S
"""
root = K.child
print root
if root == {}:
"""
The point is located
"""
print K
return K
else:
"""
The point is in the child of root
"""
print 'Here'
for i in range(len(root)):
if InSide(root[i].node,p):
print DT.triangle(root[i].node)
locate(root[i],p)
break``````

It's a point location in a tree formed by subdivision of triangle. May be the recurssion is not really good. Now this is the result

``````{0: <__main__.structure instance at 0x8468d2c>, 1: <__main__.structure instance at 0x8468d4c>, 2: <__main__.structure instance at 0x8468d6c>}
Here
Triangle_2(Point_2(0.0,2.0),Point_2(6.0,-1.0),Point_2(0.0,7.0),LARGER)
{}
<__main__.structure instance at 0x8468d6c>
None``````

The None is the printing in main

Regards

The problem is in the else, you are doing recursion yes? You don't want to simply call locate, but you want to return what it returns. So change `locate(root[i],p)` to `return locate(root[i],p)` Cheers.

Ya, it works, thanks!!