def readlog(s):
    with open(s, 'r', encoding='utf-8', errors='ignore') as f:
        a=f.read()
        print(a)

def readlineslog(s):
    with open(s, 'r', encoding='utf-8', errors='ignore') as f:
        ls = f.readline()
        print(ls)
    return ls

def tellPos(s, n):
    if n == 0:
        return 0
    else:
        c = 0
        with open(s, 'r', encoding='utf-8', errors='ignore') as f:
            while 1:
                  line = f.readline()
                  c += 1
                  if c == n or line == '':
                      break
            pos = f.tell()
        return pos

def readlinelog(s, startline , endline):
    pos = tellPos(s,startline)
    c=0
    with open(s, 'r', encoding='utf-8', errors='ignore') as f:
        f.seek(pos)
        while 1:
            line = f.readline()
            print(line)
            c += 1
            if c >= endline - startline or line == '':
                break

s = r'D:\text.txt'
ls = readlinelog(s,2,14)
print(ls)

ls = readlinelog(s,2,14)

其中的2,14 代表起始行和结束行。

可进行自行更改(比如设置为用户自己输入,或按照需求自我调试)

Logo

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。

更多推荐