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 delete a file
- Python program to copy odd lines of one file to other
- Python Program to merge two files into a third file
- Python program to extract Email-id from URL text file
- Python program to Count the Number of occurrences of a key-value pair in a text file
- reStructuredText | .rst file to HTML file using Python for Documentations
- Python program to read character by character from a file
- Python program to read file word by word
- Python Program for Binary Insertion Sort
- Python program to convert floating to binary
- Python program to convert decimal to binary number
- Python Program for Binary Search (Recursive and Iterative)
- Python Program to Count number of binary strings without consecutive 1's
- Python | Converting String content to dictionary
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. 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.