Using python to delete specified text from thousands of old blog posts

No need to over complicate things by developing a script to do what you want and to end your misery. You can do this using SQL, presuming you have access to the database.

If you are using MySQL 8+, you can use PREG_REPLACE in a query, as suggested in this SO article: How to remove all tag from column using a SQL query

UPDATE wp_posts
SET post_content = REGEXP_REPLACE(post_content, '<img.*?/>', '')
WHERE post_content LIKE '%<img%';

Note – it is strongly recommended to make a back up of your website or, at least, the database before doing any SQL operations.