(infile, n=10)
| 232 | output_file.close() |
| 233 | |
| 234 | def print_file(infile, n=10): |
| 235 | # 打开文件并读取前10行 |
| 236 | with open(infile, 'r') as file: |
| 237 | for i in range(n): |
| 238 | line = file.readline() |
| 239 | if line: # 检查是否还有行可读 |
| 240 | print(line.strip()) |
| 241 | else: |
| 242 | break # 如果文件行数少于10行,提前退出 |
| 243 | |
| 244 | def count_lines(filename): |
| 245 | with open(filename, 'r', encoding='utf-8') as file: |
nothing calls this directly
no outgoing calls
no test coverage detected