import re with open('_get_instance_details.php', 'r', encoding='utf-8') as f: content = f.read() content = content.replace('name="" name=""', 'name=""') # Also fix the trailing slash from my earlier mistake `` just to make it clean `>` content = content.replace('/>', '>') with open('_get_instance_details.php', 'w', encoding='utf-8') as f: f.write(content) print("Cleaned up duplicates.")