def main(): wordf.delete([output]) with open(filename, 'r', encoding='UTF-8') as file: #读入文件,按行操作 for line in file: with open(output, 'a', encoding='UTF-8') as out: a = wordf.style(key, line, WIDTH) a = ''.join(a) out.write(a) out.close()
def main(): with open(filename, 'r', encoding='UTF-8') as file: #打开文件 for line in file: #遍历每行 # print(takeElem(line)) list1.append(line) list1.sort(key=takeElem) wordf.delete(['1.txt']) with open(outfile, 'a', encoding='UTF-8') as out: #打开文件 list = ''.join(list1) out.write(list.replace('/', ''))
def main(): number = 29 #页码 count = 1 #行数 flag = '' #用于在行尾添加数字 wordf.delete([output]) with open(filename, 'r', encoding='UTF-8') as file: #读入文件,按行操作 for line in file: tmp = line.rstrip() with open(output, 'a', encoding='UTF-8') as out: if line[0] >= 'A' and line[0] <= 'z': a = wordf.style(key, line.rstrip(), WIDTH) a = a + [flag] + ['\r'] #末尾添加数字 a = ''.join(a) out.write(a) elif tmp == str(number): flag = ' ' + str(number) #数字前得隔着几个空 out.write(str(number)) out.write('\r') number -= 1 out.close() count += 1
import wordf filename = 'word/word.txt' keyname = 'word/a.txt' outfile1 = 'word/filted.txt' wordf.delete([outfile1]) def main(): count = 0 keys = keykey(keyname) for i in range(len(keys)): keys[i] = keys[i].replace(' ', '').rstrip() print(keys) with open(filename, 'r', encoding='UTF-8') as file: for line in file: line = line[:20].replace(' ', '').rstrip() flag = 1 for key in keys: if key.replace(' ', '') == line: count += 1 flag = 0 if flag == 1 and line >= 'A' and line <= 'z': with open(outfile1, 'a', encoding='UTF-8') as out: out.write(line) out.write('\r') print(count) def keykey(keysfile):