Home Accessing attributes of user defined object leads to "TypeError: object does not support indexing"
Reply: 0

Accessing attributes of user defined object leads to "TypeError: object does not support indexing"

user1324
1#
user1324 Published in April 26, 2018, 7:45 am

I have a class called LineString that consists of a list of Point objects. For example;

points = [Point(2,3), Point(7,8), Point(5,7)]

lin = LineString(points)

I want to write a function under LineString class that checks each point coordinate and returns (minimum_y, minimum_x, maximum_y, maximum_x).

Here is my Point class:

class Point(object):    
    def __init__(self, x, y):
        try:
            self.x = float(x)
            self.y = float(y)
        except ValueError as e:
            print(e)
            raise ValueError("x and y must be floating point numbers!")

And here is the LineString class

class LineString(points):
    def __init__(self, points):
        self.points = points

    def bounds(self):

        for point in points:
            x = point[0] 
            y = point[-1] 
            minx = min(x) 
            miny = min(y) 
            maxx = max(x) 
            maxy = max(x)    
            return (miny, minx, maxy, maxx)

I couldn't write the correct code to return the function minimum and maximum x,y values. When I run this, I get that:

x = point[0]
TypeError: 'Point' object does not support indexing"
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.34115 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO