top of page

~Fundamental Product Programming Skill (Replacing Words Within Text Documents)~

  • Writer: Archie
    Archie
  • Mar 19, 2019
  • 1 min read

Using a python program and changing it I made a .txt file displaying the story 'Robin Hood' replace any instance where 'Robin' or 'Robin Hood' is present for 'Shrek'.

ree
Original .txt file.

To start off, I went online and downloaded a .txt file for Robin Hood and opened up the following program.

ree

This program finds a file called 'RobinHood.txt', the name of the file I want to change.

Once the program finds this I use the 'find' and 'replace' keywords to replace any instance of 'Robin Hood' and 'Robin' with 'Shrek' and to then take this edited file and make it into a new copy called 'Shrek.txt' and leave it there.

ree
New edited file.

The following, more complex program does the same thing but allows you to manually decide on files and text replacements during runtime, the result is the same.

ree

Recent Posts

See All

Comments


bottom of page