(Python) To find a mistake in a text file

Asked 1 years ago, Updated 1 years ago, 111 views

fname = input('Enter the file name: ')
try :
    fname = open(fname)
except :
    print('Wrong file name')
    exit()
for line in fname :
    line = line.rstrip()
    if line.startswith('X-DSPAM-Confidence: 0.8475') :
        print(line)
    count = 0
    # # line = line[20:]
    # # line = float()
    if line.startswith(line):
        count = count + 1
print ('There are', count, float(0.8475)'lines in', line)


*This code is in progress in the way I heard during the Cocera class. The above is not a task, and completing the above code does not help my credit or anything else. Reveals that it's purely personal study.

A code that identifies a specific sentence in a text file and calculates how many mistakes there are in the entire test.

I succeeded in printing up to 'X-DSPAM-Confidence:0.8475' in the text file, and I even made 0.8475 a mistake, but I don't know how to find these 0.8475s. .startswith doesn't support mistakes, what should I do in this case? I'd appreciate it if you could answer me.

python float method

2022-09-21 16:30

1 Answers

Hi, how are you?

Wouldn't this work?

import re

print re.findall(‘\d+.\d+‘, ‘abc:0.8475’)


2022-09-21 16:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.