import xlrd
fname = "D://tesx.xlsx"
bk = xlrd.open_workbook(fname)
shxrange = range(bk.nsheets)
try:
except:
sh = bk.sheet_by_name("Sheet1")
print("no sheet in %s named Sheet1" % fname)
# 获取行数
nrows = sh.nrows
# 获取列数
ncols = sh.ncols
print("nrows %d, ncols %d" % (nrows, ncols))
# 获取第一行第一列数据
cell_value = sh.cell_value(1, 1)
# print cell_value
table = []
# 获取各行数据
for i in range(0, nrows):
row_data = sh.row_values(i)
table.append(row_data)
print(table)
# attribute_name = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
attribute_name = []
# attribute_name = ['a', 'b', 'c', 'd']
for i in range(0, len(table[0])):
i = i+97
attribute_name.append(chr(i))
print('属性集', attribute_name)
# def compare(a, b, col):
if a != b:
print(attribute_name[col], end='')
else:
print('*', end='')
#
#
#
#
#
# #梯形输出差别矩阵
# for i in range(0, len(table)):
#
#
for j in range(0, i):
element = []
#
#
print(end='\t\t')
if table[i][len(table[0])-1] !=
table[j][len(table[0])-1]:
#
#
for column in range(0, len(table[0])-1):
compare(table[i][column],
table[j][column], column)
else:
print('*', end='\t')
print('')
#
#
#
#
#
element_set = []
#
# attribute_name = ['a', 'b', 'c', 'd', 'e']
#
for i in range(0, len(table)):
for j in range(0, len(table)):
if table[i][len(table[0])-1] !=
table[j][len(table[0])-1]:
element = []
for column in range(0, len(table[0])-1):
if table[i][column] != table[j][column]:
element.append(attribute_name[column])
element_set.append(element)
else:
continue
print('差别矩阵')
print(element_set)
A = []
B = []
C = []
D = []
for i in element_set: #去重
if not i in B:
B.append(i)
print('去掉重复元素')
print(B)
print('按长短排序开始')
def paixu():
for i in range(0, len(B)):
for j in range(i, len(B)):
if len(B[i]) > len(B[j]):
a = B[i]
B[i] = B[j]
B[j] = a
print(B)
paixu()
print('开始吸收')
n = 0
while n <= len(B):
C = B.copy()
for i in range(n+1, len(B)):
if set(B[n]) & set(B[i]) == set(B[n]):
C.remove(B[i])
B = C[:]
n = n+1
print(B)
print('开始分配')
def f(n):
if n ==1:
print(C[0])
return C[0]
else:
B = []
for s in f(n-1):
for m in C[n-1]:
if set(s) & set(m) == set(m):
B.append(s)
break
else:
B.append(s+m)
print(B)
return B
D=f(len(C))
print('开始-排序')
for i in range(0, len(D)):
for j in range(i, len(D)):
if len(D[i]) > len(D[j]):
a = D[i]
D[i] = D[j]
D[j] = a
print(D)
print('开始吸收')
n = 0
while n <= len(D):
C = D.copy()
for i in range(n+1, len(D)):
if set(D[n]) & set(D[i]) == set(D[n]):
C.remove(D[i])
D = C[:]
n = n+1
print(C)