Given a binary file that contains some sentences (space separated words), let’s write a Python program to modify or alter any particular word of the sentence.
Step 1: Searching for the word in the binary file.
Step 2: While searching in the file, the variable “pos” stores the position of file pointer record then traverse(continue) reading of the record.
Step 3: If the word to be searched exists then place the write pointer (to ending of the previous record) i.e. at pos.
Step 4: Call
write() function to take the new record.
Step 5: Write the new object at the position “pos” and hence the record is updated and print “record successfully updated”.
Step 6: If the word does not exists then print “record not found”.
Let’s suppose the content of the binary file is:
- Python program to reverse the content of a file and store it in another file
- Python Program to Reverse the Content of a File using Stack
- Python - Append content of one text file to another
- Python Program to delete a file
- Python Program to merge two files into a third file
- Python program to copy odd lines of one file to other
- Python program to extract Email-id from URL text file
- Python program to Reverse a single line of a text file
- Python program to Count the Number of occurrences of a key-value pair in a text file
- Modify XML files with Python
- How to Parse and Modify XML in Python?
- Python | Modify Equal Tuple Rows
- Python - Modify Equal Tuple Rows
- reStructuredText | .rst file to HTML file using Python for Documentations
- Create a GUI to convert CSV file into excel file using Python
- Python Program for Binary Insertion Sort
- Python program to convert floating to binary
- Python program to read file word by word
- Python program to read character by character from a file
- Python program to convert decimal to binary number
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.