bwaha wrote: > I'd appreciate some experience from the gurus out there to help me > understand how to implement MVC design in python code. >
######## Model ######## class Study(object): def __init__(self, name, file): self.name = name self.file = file class Project(object): def __init__(self, name): self.name = name self.studies = [] ######## End Model ######## data=''' BEGIN PROJECT "mpi6_0" STUDY "Cyc0302_0" cyc0302_beanoz_x1.sdy STUDY "Cyc0305_0" cyc0305_beanoz_x1.sdy STUDY "Cyc0308_0" cyc0308_beanoz_x1.sdy STUDY "Cyc0311_0" cyc0311_beanoz_x1.sdy STUDY "Cyc0314_0" cyc0314_beanoz_x1.sdy END PROJECT BEGIN PROJECT "mpi6_1" STUDY "Cyc0302_1" cyc0302_beanoz_x1.sdy STUDY "Cyc0305_1" cyc0305_beanoz_x1.sdy STUDY "Cyc0308_1" cyc0308_beanoz_x1.sdy STUDY "Cyc0311_1" cyc0311_beanoz_x1.sdy STUDY "Cyc0314_1" cyc0314_beanoz_x1.sdy END PROJECT ''' if __name__ == '__main__': import StringIO src = StringIO.StringIO(data) projects = [] for line in src: parts = line.split(' ') begin = parts[0] == 'BEGIN' studyline = parts[0] == 'STUDY' end = parts[0] == 'END' if begin == True: project = Project( parts[2][1:-1] ) elif studyline == True: project.studies.append( Study(parts[1][1:-1], parts[2]) ) elif end == True: projects.append( project ) for proj in projects: print 'PROJECT: ', proj.name for study in proj.studies: print '---- ', study.name -- http://mail.python.org/mailman/listinfo/python-list