""" __author__ :qin __content__:extract part of content of a file __date__:2020/8/11 """ import easygui import os path = easygui.fileopenbox(default="D:statistics_chengqichaoExtractRoadMarking_CASE_1*.xyz") # path是打开的文件的全路径 linecount=100 # how much rows to be extracted i=0 if path: # 如果选择打开文件,没有选择取消 b = os.path.splitext(path) # 把打开的文件的全路径分割成文件名和后缀名 c = [b[0], '_part', '.xyz'] # 文件名加上其他字符变成想要的文件名,相当于在原来的路径下修改一下文件名 d = ''.join(c) # 要写入的文件的名字, with open(d, 'w+') as f1: with open(path, 'r', encoding='utf-8') as f: for line in f: i=i+1 f1.writelines(line) # 写入文件 if i==100: break