python
txt文件中部分内容如下:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOYAAAB/CAYAAAD7A74wAAAN3klEQVR4nO1dS7LkKAz0ubzq03COPoJPwxlmOYvZ+TDMovzhI4HA2KhcmRFER9cr25giQRIimf779x/XWqZpCv6Vfl/6ueR7V599V5mmiS3Ud668p+Z2Kb1b6fmSPiPtVzX97+l2Sf5+V4O3NnLt9Vo64P6MeLDi/pW2JUfqlnbR0AFbiFkawK60y9U+ebWvsOVK56v5W69GkMw4TzaytNNIiZmbXVvaJddGTw1WpQ5Z6rSt/THX3rUD3dNFTExJI5W+26shWon8aMNmOkRLHXt95+l2uTpj9ngXTe1SnClbZ0wUFJT7C4iJgqKwgJgoKAoLiImCorCAmCgoCguIiYKisEz//fuP+/v3LwoKiqJyEPPPnz8oKChKSkBMAAB0AMQEAIUYTMzVLWZxq3POWeOmaXLGXr3l4uZpctPlGxUf5Kxdy1+zxk3T7BbBV++AtXe3A3AHhhBzXeYwL9DYTweeF2fX9SBXC7esmdw0z85UM8E6I81j9MpceI41k5sX69b9a/vAwRbj0tduq1vQvkKsy+ymeRssgWF4hpjbbHh05nlOO8tGzLNDbJ2xhp3r4uZtdloX02mWss5kZrzVWr4Tr4ub405OfXb8aS4S3f8u1Tbk59YSZC/ce+AsD0iIuS5u7m0WWpN2HqrDWsPMIBRWt8z+DLa6ZZZem61slpj5+hDPH0HMauwzdI/2a0RsWfzYLM4Q89PJW0whEThiXugItAlmnbnaubxZuO4yb8b2rQGlxLQmbKfPrDmImElf2PrjD5GzOGP2GYEjVBDTGsHInZtZL/iruXplYU00c09uNouzq0tngkqf9axWb2JOkflq3TLIliXfoXGA/FY8QMxo9uXKPJMd9vPoTCcJSBmbs8dLfO7dMuJmibm6ZU47y7p6H8S+s9oZUz4o3A1ytr5oUX0b9MyYlC9nl/wImQSM9o8pEvqRzfA5n9niSuFG8s9AYUIb8VFi7hFw8if02ldCTGs6LGc1gWjHl0MRMePZJx+AyNeLD9jsEcdZGB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YnDNH8KUlwMNHk7QGE6d+TmNGzSsRscANyg9ddyyXXpUVl2lTvJmbPA4VyUKn5UxqUehKzZILKiLnuxy9ICFUYlC4lGGSj8J2O3ChoU72TmCLfqxeUav5kZ0vnuHqLorIuSh4oDoA8MRcT/z7nsgivV1RWU2jOlRXJtfQ6pIpfW34nMR/EUM2f/EWydb8kqCMN/szZjhWCIGbBGjgis/F9iwMOX+dvAoh5AT+l+cNBdMJVnx04NX58m6i1HoCYAKAQICYAAN0AYgKAQoCYAKAQICYAKASICQAKAWICgEKAmACgECAmACgEiAkACgFiAoBCgJgAoBAgJgAoBIgJAAoBYgKAQoCYAKAQICYAKASICQAKAWICgEKAmACgECAmACgEiAkACgFiAoBCgJgAoBAgJgAoBIgJAAoBYgKAQoCYAKAQICYAKASICQAKAWICgEKAmACgECAmACgEiAkACgFiAoBC/A/Oj6zY5SHxzAAAAABJRU5ErkJggg==
txt中有三列内容,第一列为序号。第二列为内容,第三行为标签,现在我想将第三列标签全为3的的内容重新写到另一个txt上
请问该怎么写?求大佬指点,万分感谢!
本帖最后由 Minecraft程序猿 于 2021-2-8 20:26 编辑
with open("text.txt", 'r') as f:
new = ""
for each_line in f:
count = 0
c = 0
#each_line = each_line[:-1]
for each in each_line:
if each in {' ', '\t'}:
count += 1
if count == 1:
co = c
elif count == 2:
cox = c
if (each_line == (len(each_line) * '3')) or (each_line == (len(each_line) * '3') + '\n'):
new += each_line
new += '\n'
c += 1
with open("new.txt", 'w') as n:
n.write(new)
试试吧,我没测试过,报错了或有bug再来问我这个程序是检测由Tab或空格分隔的列
页:
[1]