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();View Code
标签:__,txt,python,截取,lines,file,line,文本,open From: https://www.cnblogs.com/lljboke/p/17586334.html