Python脚本需要帮助添加一个export.txt到i

2024-04-26 05:00:24 发布

您现在位置:Python中文网/ 问答频道 /正文

f = open('f.txt', 'r')
import re

for line in f:
    u = line.split(':')[0]
    p = line.split(':')[1]
    m = re.search(r'\d+$', u)

    if m is not None:
        m1 = re.search(r'\d+',p)
        if m1 is None:
            print(u + ':' + p.rstrip() + m.group())
f.close()

f = open('f.txt', 'r')
for line in f:
    l = line.rstrip().split(':')[1]
    m = re.search(r'\d+', l)
    if m is None:
        print(line.rstrip() + '123')
f.close()

f = open('f.txt', 'r')
for line in f:
    l = line.rstrip().split(':')[1]
    m = re.search(r'\d+', l)
    if m is None:
        print(line.rstrip() + '1')
f.close()

f = open('f.txt', 'r')
for line in f:
    u = line.split(':')[0]
    p = line.split(':')[1]
    m = re.search(r'\d+$', u)

    if m is not None and len(m.group()) == 4:
        if int(m.group()) < 2013 and int(m.group()) > 1950:
            m1 = re.search(r'\d+$',p)
            if m1 is None:
                print(u + ':' + p.rstrip() + m.group()[2:])
f.close()

f = open('f.txt', 'r')
for line in f:
    s = line.split(':')[1]
    m = re.search(r'\d+', s)

    if m is not None:
        newone = line.split(':')[0] + ':' + re.sub(r'\d+',"", s).rstrip()
        if newone[-1:] != ':':
            print(line.split(':')[0] + ':' + re.sub(r'\d+',"", s).rstrip())
f.close()

这是我的.py脚本,我已经做了,它工作得很好,但它不导出一个.txt一旦它完成编辑所有的行在f.txt-它只是关闭

我可以得到一些帮助,添加一些代码,使其导出为finished.txt-提前感谢


Tags: inretxtnoneforclosesearchif