python截取文本
def sclip(): with open("file.txt", "r") as file: lines = file.readlines() first_line = lines[0:2] last_10_lines = lines[5:] first_line.extend(last_10_lines) with open("output.txt", "w") as file: file.writelines(first_line) file.writelines(last_10_lines) def getCharByLine(char,lines): for i, line in enumerate(lines): index = line.find(char) if index != -1: return i + 1; return None if __name__ == '__main__': # with open("file.txt", "r") as file: # lines = file.readlines() sclip();