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:
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- 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
- Upload file and read its content in cherrypy python
- How to Parse and Modify XML in Python?
- Python | Modify Equal Tuple Rows
- Python - Modify Equal Tuple Rows
- Modify XML files with Python
- Modify the string such that it contains all vowels at least once
- Modify Numpy array to store an arbitrary length string
- How to modify existing figure instance in Matplotlib?
- reStructuredText | .rst file to HTML file using Python for Documentations
- Create a GUI to convert CSV file into excel file using Python
- Python - Get file id of windows file
- MoviePy – Getting Original File Name of Video File Clip
- PYGLET – Opening file using File Location
- PyCairo - Saving SVG Image file to PNG file
- Python | Converting String content to dictionary
- response.content - Python requests
- Python program to extract Email-id from URL text file