from os import listdir
fn = 'data.txt'
origin = listdir('.')
"""
s='''
id || name || age
1 || jie || 28
2 || ping || 25
'''
with open(fn, 'w') as f:
f.write(s)
"""
with open(fn) as f:
s = f.read()
L = s.strip().split('\n')
LL = [[j.strip() for j in i.split('||')] for i in L]
collumn_names = LL[0]
c_len = len(collumn_names)
collumns = [set() for i in range(c_len)]
for i in LL[1:]:
for j in range(len(i)):
collumns[j].add(i[j])
for i, j in zip(collumn_names, collumns):
with open(i + '.txt', 'w') as f:
f.write('\n'.join([i] + sorted(j)))
print('new files: ', ', '.join([i for i in listdir('.') if i not in origin]))
导入数据库,一条去重语句搞定