Given that CSV files are simple text files, the best solution to update their content is to read them, change them to internal Python objects, and then write the result in the same format. In this recipe, will see how to do this.
In this recipe, we will use the movies.csv file that is available on GitHub at https://github.com/PacktPublishing/Python-Automation-Cookbook/blob/master/Chapter06/movies.csv. It contains the following data:
|225.7||Gone With the Wind||1939|
|161.0||ET: The Extra-Terrestrial||1982|
Notice that the year of Star Wars is incorrect (it should be 1977). We'll change it in the recipe.