How to import a list of python txt files and modify a specific string...

Asked 2 years ago, Updated 2 years ago, 18 views

Currently, I have to change 21 of those txt files to 2, what should I do with Python? I think it's going to work, but I'm struggling because it's not working. Please let me know.

python

2022-09-20 17:54

1 Answers

textname = ''

with open(f'{textname}.txt', 'r') as txt:
    a = txt.read()
a = a.replace('21 ', '2 ')
with open(f'{textname}.txt', 'w+') as txt:
    txt.write(a)


2022-09-20 17:54

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.