usr bin env python -coding utf8- import re rows 192 168 102 115 Шкерин

 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
#! /usr/bin/env python
#-*-coding:utf8-*-
import re
rows = [["192.168.102.115",'Шкерин Николай Вячеславович','Ленина',' 2г',' 15']
,['192.168.102.35','Ткачёв Антон Николаевич','Ленина',' 2в','2']
,['192.168.102.35','Ткачёв Антон Николаевич','Пушкина',' 2в','2']]
def bin2ip(ip):
return ip
re_num = re.compile('(?P<num>\d+)(?P<lit>.*)')
def numericCompare(x, y):
print re_num.search(x).groups()
xnum, xlit = re_num.search(x).groups()
ynum, ylit = re_num.search(y).groups()
if xnum > ynum:
return 1
elif xnum == ynum:
if ylit == xlit: return 0
elif ylit < xlit: return 1
else: return -1
else:
return -1
#cursor = conn.cursor()
#cursor.execute("select segment, accounts.name, accounts.street, accounts.bnum, accounts.apart from staff, vgroups, acc_list, accounts where staff.vg_id=vgroups.vg_id and acc_list.vg_id=vgroups.vg_id and acc_list.uid=accounts.uid limit 100,5;")
#rows = cursor.fetchall()
l = []
for row in rows:
l.append([bin2ip(row[0])] + [r for r in row[1:]])
import operator
l = sorted(l, numericCompare, key=operator.itemgetter(4))
l = sorted(l, numericCompare, key=operator.itemgetter(3))
for each in sorted(l, key=operator.itemgetter(2)):
s = ';'.join(each[:2] + [' '.join(each[2:])]) + '\n'
print s
#cursor.close()
#if __name__=='__main__':
# main()