Skip to content
Advertisement

Replacing a word in a text file with a value using python

I have been trying to replace a word in a text file with a value (say 1), but my outfile is blank.I am new to python (its only been a month since I have been learning it).

My file is relatively large, but I just want to replace a word with the value 1 for now. Here is a segment of what the file looks like:

JavaScript

I want to first replace the word ATOM with the value 1. Next I want to replace #ORB with a space. Here is what I am trying thus far.

JavaScript

Can anyone offer any suggestions or help? Thanks so much.

Advertisement

Answer

Use replace.

JavaScript

Untested code:

JavaScript

Working example.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement