MCPcopy Create free account
hub / github.com/Cats-Team/AdRules / read_file

Function read_file

script/utils.py:6–18  ·  view source on GitHub ↗

读取文件并返回行列表

(file_path, skip_comments=True)

Source from the content-addressed store, hash-verified

4from datetime import datetime, timezone, timedelta
5
6def 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
20def write_file(file_path, lines):
21 """将行列表写入文件"""

Callers 2

generate_singboxFunction · 0.90
generate_surgeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected