Your application needs to write user data into a file. To ensure data consistency, even if the application crashes during a write operation, what measure would you take?
- Enable automatic file versioning to track changes and ensure consistency.
- Use a try-except block to handle crashes and continue writing.
- Use file locking to prevent other processes from accessing the file during writes.
- Write data to a temporary file and then replace the original file.
To ensure data consistency, write data to a temporary file first, and then replace the original file. This way, if the application crashes during writing, the original file remains intact.
Loading...
Related Quiz
- Which Matplotlib function allows plotting data points in the form of a two-dimensional density plot?
- How would you ensure that a piece of code in a module is only executed when the module is run as a standalone program and not when it is imported?
- When iterating over a dictionary's items, each item is presented as a _______.
- When implementing a recursive algorithm, what is crucial to avoid infinite recursion?
- How can you remove all items from a Python set?