Python - AttributeError
Question: So for a line class I'm doing, I keep getting an error that says

    
    
    AttributeError: Line instance has no attribute 'point0'
    

I'm declaring the line like this:

    
    
    def __init__(self, point0, point1):
        self.x = point0
        self.y = point1
    
    def __str__(self):
        return '%d %d' % (int(round(self.point0)), int(round(self.point1)))
    

And I get the x and y from my point class which should already be float values
so I don't need to check for an error in my init method however I do check to
see if point0 and point1 are floats in my rotate method:

    
    
    def rotate(self, a):
            if not isinstance(a, float) or not isinstance(self.point0, float) or not isinstance(self.point1, float):
                raise Error("Parameter \"a\" illegal.")
            self.point0 = math.cos(a) * self.point0 - math.sin(a) * self.point1
            self.point1 = math.sin(a) * self.point0 + math.cos(a) * self.point1
    

So why does python keep saying that it has no attribute point0? I also tried
changing my _init_ method to look like this:

    
    
    def __init__(self, point0, point1):
        self.point0 = point0
        self.point1 = point1
    

But when I do that the error says point0 has no attribute float. So why do I
keep getting this error? Here's the code I'm using to test:

    
    
    p0 = Point(0.0, 1.0)
    p1 = Point(2.0, 3.0)
    line = Line(p0,p1)
    print line
    


Answer: I'm curious... how much do you know about scope in Python?

In your class, you have a member variable named x and another named y. Your
**init** function accepts an argument called point0 and another called point1.
It saves point0 in the x member variable, and point1 in y. Then, in your
rotate function, you attempt to access a variable called point0. Do you see
the problem?

An important thing to understand when programming (and this is true in most
programming languages, if not all of them) is that the name of an argument
doesn't affect the name of that data elsewhere. I can pass a variable called
foo into a function that takes an argument called bar. In that function, I
have to refer to the data as bar because that's the name of the variable.
Later, after I've called that function, the name of the variable is still foo,
because only the variable inside the function is called bar. Does that make
sense?

