How to selectively delete lines?
📁 Advanced Python Topics, example
There is a file consisting of lines. I need to selectively delete lines that start with a certain set of characters using Python. How can I do this?
Here is an example
ATOM 14ATOM 15ANISOU 15ATOM 16ANISOU 16I need to delete everything that starts with ANISOU
As an option, if you have systemd
sudo nano /etc/systemd/system/<your_bot_name>.serviceCopy the following text there, replacing the text in <> with your parameters:
[Unit]Description=<YOUR BOT DESCRIPTION>After=network.target[Service]Type=simpleUser=<username under which you run scripts>Group=<user group under which you run scripts>Environment=PYTHONPATH=</full/path/to/directory/with/your/script> WorkingDirectory=</full/path/to/directory/with/your/script>ExecStart=</full/path/to/python> </full/path/to/your/script>Restart=alwaysRestartSec=5[Install]WantedBy=network.target
Log in to leave an answer
Blogs