usr bin python coding utf-8 import re codecs proffs class Proff def __

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/python
# coding: utf-8
import re, codecs
proffs = []
class Proff:
def __init__(self, firstname='', secondname='', lastname='', faculty='', address='', phone='', email=''):
self.firstname = firstname # имя
self.secondname = secondname # отчество
self.lastname = lastname # фамилия
self.faculty = faculty
self.address = address
self.phone = phone
self.email = email
f = codecs.open('list.txt', 'r', 'utf-8')
text = f.read()
f.close()
records = text.split('\r\n\r\n')
for rec in records:
lines = rec.split('\r\n')
name = lines[0].split(' ')
if len(name) == 2:
secondname = ''
lastname, firstname
elif len(name) == 3:
lastname, firstname, secondname = name
else:
lastname, firstname = name[:2]
secondname = ' '.join(name[2:])
faculty = lines[1]
address = phone = email = ''
info = lines[2:]
for line in info:
address_match = re.match('^Адрес\: (.*?)$', line)
phone_match = re.match('^Телефон\: (.*?)$', line)
email_match = re.match('^E-mail\: (.*?)$', line)
if address_match:
address = address_match.group(1)
if phone_match:
phone = phone_match.group(1)
if email_match:
email = email_match.group(1)
proff = Proff(firstname, secondname, lastname, faculty, address, phone, email)
proffs.append(proff)
# Выводим всё на экран:
for proff in proffs:
print u'> ФИО: %s %s %s' % (proff.lastname, proff.firstname, proff.secondname)
print u'> Отделение: %s' % proff.faculty
print u'> Адрес: %s' % (proff.address or u'(не указан)')
print u'> Телефон: %s' % (proff.phone or u'(не указан)')
print u'> E-mail: %s' % (proff.email or u'(не указан)')
print