Firstly, I would like to apologize for the massive number of nooby crap questions that come out of my account. I'm an emerging programmer that doesn't always know what he's doing, so I'm sorry.

Secondly, the problem. I'm writing this code:

class Object():
    def __init_(self, vertices, color, name):
        self.color = color
        self.name = name
        self.vertices = vertices ##Vertices is in list form

    def editVertice(self, vertice):
        if vertice in self.vertices:
            self.vertices.index(vertice)
        else:
            print "ERROR: VERTICE NOT RECOGNIZED.  INSERT VALID VERTICE"

The problem I'm having is that when I run this, it gives an error saying that the term 'vertice' in the function editVertice is not recognized, even though its clearly being called in the function. (Yes, I am calling the class and function later in the code, but seeing as its over a 180 lines I thought it might be a good idea just to leave it be). I have no idea why. Any help would be appreciated. I would prefer not to scrap the code, but I can if need be. Thanks in advance!

Recommended Answers

All 3 Replies

it gives an error saying that the term 'vertice' in the function editVertice is not recognized

Can you post (as code) the complete error message sent by python instead of your own interpretation of this message ?

Also it is much better to raise an exception than to print an error message in your function. Use

raise RuntimeError("VERTICE NOT RECOGNIZED.  INSERT VALID VERTICE")

Heres the error:

Traceback (most recent call last):
    File "C:...", line 106, in <module>
        tempobject.editVertice((100, 100))
    File "C:...", line 94, in editVertice
        if vertice in self.vertice:
AttributeError: Object instance has no attribute 'vertice'

Thanks for the explanation of what raise does, I always wondered yet never looked it up.

if vertice in self.vertice: should be if vertice in self.vertices:.
It is not a very good idea to use both vertice and vertices. You could write if ver in self.vertices: for example and use ver instead of vertice.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.