top of page

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

Writer's picture: ArchieArchie

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'.

Original .txt file.

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

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.

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.


1 view0 comments

Recent Posts

See All

Comments


bottom of page