W
W
werastet2021-08-02 10:42:37
Python
werastet, 2021-08-02 10:42:37

Generator and validation?

Good day guys, please help me, I have a script for generating a certain value, this value is written in the script (add) and I need this value to be checked from the 1.txt file (in the same directory) and if I generate the value that is in the 1.txt file saved to file all. txt
.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2021-08-02
@lob4Noff

string = '' # значение, которое будет проверяться в файле 1.txt 

with open('1.txt', 'r') as file_c:
    for line in file_c:
        if string == line.replace('\n', ''):
            with open('all.txt', 'a') as file_w:
                file_w.write(string)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question