Background: I have a class called Project, saved as project.py, located at Project5.prod.project.Project in Eclipse. I have another class called Repository, which is a list that Projects are added to. As a safety precaution, I'm validating all Projects to make sure they are of type Project (so random strings and stuff don't get added).
import Project5.prod.project.Project class Repository(object): def __init__(self): #constructor self.theContainer =  def addProject(self, proj): #validation for project if(isinstance(proj, project.Project) == False): #error here raise ValueError("Repository.addProject: Invalid project.")
To figure out exactly what type my proj is, I added a project to the repository successfully, using both of these methods.
hist = ProjectHistory() myProject = project.Project(1, 10, 15, 20, 100, 200) print type(myProject), "type" hist.addProject(myProject) hist.addProject(project.Project(2, 10, 15, 20, 100, 200)) print type(project.Project(2, 10, 15, 20, 100, 200)), "type"
Both times, the type is printed to the screen as: <class 'Project5.prod.project.Project'>
However, using the line above, the following error is produced:
if(isinstance(proj, project.Project) == False):
UnboundLocalError: local variable 'project' referenced before assignment
No matter what I enter (Project5.prod.project.Project, project.Project, etc.), the first value is always referenced before assignment. The thing that I don't get is that it isn't a variable...it's supposed to be an object. What's the problem here? I don't get it.