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 - Modify Equal Tuple Rows
- Python | Converting String content to dictionary
- Python program to copy odd lines of one file to other
- Python Program to delete a file
- Python Program to merge two files into a third file
- Python program to Count the Number of occurrences of a key-value pair in a text file
- Python program to read character by character from a file
- Python program to read file word by word
- Python program to Reverse a single line of a text file
- Python Program for Binary Search (Recursive and Iterative)
- Python Program for Binary Insertion Sort
- Python program to convert floating to binary
- Python Program to Count number of binary strings without consecutive 1's
- Python program to convert decimal to binary number
- Python Program to Generate Random binary string
- Python Program to Convert any Positive Real Number to Binary string
- Python | Reading an excel file using openpyxl module
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.