Python 2.3 Windows XP
We have a builtin module 'point'. I am trying to determine a better way to check the type of a list of 'point' objects. A point object is created:
Original code:
Improved code:
This does not work:
I am confused about what 'type' of object 'pt1' actually is.
We have a builtin module 'point'. I am trying to determine a better way to check the type of a list of 'point' objects. A point object is created:
Code:
from point import Point pt1 = Point(x_coord, y_coord, z_coord) print type(pt1) <type 'point'> print dir(pt1) ['dist']
Code:
def chk_type(p_list): ret_list = [] for p in p_list: if type(p) == type(Point(0,0,0))): ret_list.append(True) else: ret_list.append(None) return ret_list if None not in chk_type([p1, p2, p3]): .....do stuff
Code:
def chk_type(p_list): for p in p_list: if not isinstance(p, type(Point(0,0,0))): return False return True if chk_type([p1, p2, p3]): ........do stuff
Code:
if not isinstance(p, Point):
Comment