读取文件并返回行列表
(file_path, skip_comments=True)
| 4 | from datetime import datetime, timezone, timedelta |
| 5 | |
| 6 | def read_file(file_path, skip_comments=True): |
| 7 | """读取文件并返回行列表""" |
| 8 | if not os.path.exists(file_path): |
| 9 | return [] |
| 10 | try: |
| 11 | with open(file_path, 'r', encoding='utf-8') as f: |
| 12 | lines = [line.strip() for line in f if line.strip()] |
| 13 | if skip_comments: |
| 14 | lines = [l for l in lines if not l.startswith(('#', '!', '['))] |
| 15 | return lines |
| 16 | except Exception as e: |
| 17 | print(f"Error reading {file_path}: {e}") |
| 18 | return [] |
| 19 | |
| 20 | def write_file(file_path, lines): |
| 21 | """将行列表写入文件""" |
no outgoing calls
no test coverage detected