1. # !/usr/bin/env python
    2. def read_File(file_name): # 读文件
    3. with open(file_name,'r') as f:
    4. list_file = []
    5. for line in f:
    6. list_file.append(line)
    7. return list_file
    8. def write_File(content, path_out): # 写文件
    9. with open(path_out,'w') as f:
    10. f.writelines(content)
    11. def do_work(file_name, file_open, file_shut, path_out, cycle_shut, cycle_open):
    12. list_file = read_File(file_name)
    13. list_open = read_File(file_open)
    14. list_shut = read_File(file_shut)
    15. list_result = []
    16. cycle = 0
    17. num = 0
    18. y = 1
    19. for line in list_file:
    20. if y % 2 != 0: # 奇数
    21. cycle = cycle + cycle_shut
    22. else: # 偶数
    23. cycle = cycle + cycle_open
    24. if num == cycle and y % 2 != 0:
    25. list_result = list_result + list_shut
    26. list_result.append(line)
    27. y += 1
    28. elif num == cycle and y % 2 == 0:
    29. list_result = list_result + list_open
    30. list_result.append(line)
    31. y += 1
    32. else:
    33. list_result.append(line)
    34. num += 1
    35. write_File(list_result, path_out)
    36. def main():
    37. cycle_shut = 3 # 周期,单位月
    38. cycle_open = 6 # 周期,单位月
    39. file_name = r'F:\2020\Lu9\work\eclipse\sch\1066\LU9_RST_1066_y.SCH'
    40. file_open = r'F:\2020\Lu9\work\eclipse\sch\1066\LU9_RST_1066_y-open.SCH'
    41. file_shut = r'F:\2020\Lu9\work\eclipse\sch\1066\LU9_RST_1066_y-shut.SCH'
    42. path_out = r'F:\2020\Lu9\work\eclipse\sch\1066\LU9_RST_1066_r.SCH'
    43. do_work(file_name, file_open, file_shut, path_out, cycle_shut, cycle_open)
    44. if __name__ == '__main__':
    45. main()