cosname

python clases relationship

Jun 25th, 2015
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.04 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. class Pupil(object):
  4.  
  5.     def __init__(self, **kargs):
  6.         self.name = kargs["name"]
  7.  
  8.     def set_group(self, group):
  9.         self.group = group
  10.  
  11. class Teacher(object):
  12.  
  13.     def __init__(self, name, subjects):
  14.         self.name = name
  15.         self.subjects = subjects
  16.  
  17. class ClassRoom(object):
  18.  
  19.     def __init__(self, slug):
  20.         self.slug = slug
  21.  
  22. class Lesson(object):
  23.  
  24.     def __init__(self, subject, classroom, teacher, group):
  25.         self.subject = subject
  26.         self.classroom = classroom
  27.         self.teacher = teacher
  28.         self.group = group
  29.         self.parts = {}
  30.  
  31.     def set_part(self, name, materials):
  32.         self.parts[name] = materials
  33.  
  34.     def provide_part(self, name):
  35.         print "Lesson part:", name
  36.         print self.parts[name]["text"]
  37.         print "----------------"
  38.  
  39.     def __del__(self):
  40.         print "Lesson", self.subject, "finished"
  41.         print "Students lectured:"
  42.         for person in self.group.pupils:
  43.             print person.name.rjust(18)
  44.  
  45. class Group(object):
  46.  
  47.     def __init__(self, name, *args):
  48.         self.name = name
  49.         self.pupils = args
  50.         for pupil in args:
  51.             pupil.set_group(self)
  52.  
  53. # Приклад використання зв’язків
  54.  
  55. t = Teacher("Roman M. Kos", ["python basics"])
  56. students = [
  57.     Pupil(name="Kostiantyn"),
  58.     Pupil(name="Sasha"),
  59.     Pupil(name="Mykyta")
  60. ]
  61. g = Group("independent students", *students)
  62. cr = ClassRoom("godocoworking")
  63. l = Lesson(subject="python classes", classroom=cr, teacher=t, group=g)
  64.  
  65. # Робота з даними і імітація реального процесу
  66.  
  67. l.set_part("introduction", {"text": "Introduction to python classes..."})
  68. l.set_part("core", {"text": "Clases are...."})
  69. l.set_part("q&a", {"text": "Now i am answering to given questions"})
  70. l.set_part("ending", {"text": "Ok, now the time of homework instructions"})
  71.  
  72. l.provide_part("introduction")
  73. l.provide_part("core")
  74. l.provide_part("q&a")
  75. l.provide_part("ending")
  76.  
  77. del l
Advertisement
Add Comment
Please, Sign In to add comment