O
O
Onervi2021-06-16 17:17:53
Python
Onervi, 2021-06-16 17:17:53

How to delete lines from another file using python code?

How to use Python code to find a match and remove from another file?
There are two files, one is running and one is just like a config.
I need to find matches in another file from the running python file and remove this line from it.
Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-06-16
@Onervi

Well, regular expressions can help you.
You loop through the lines of the source file. You check each line against a set of expressions. If there were no matches, put the lines in a temporary file, then move the temporary file to the place of the original one.
More important question - why do you need it? Trying to blacklist functions for untrusted code? So I have bad news, there are quite a few ways to get around this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question