- It creates a new file and add new data to it
- If you choose a file that already exist, it will empty the file & overwrite it
- First Way
- Opening the File in Write Mode
- Adding new data to the file
- Closing the File
- Opening the File in Read Mode to check if new data is added
- Closing the File
- Second way (open with)
- Opening the File in write mode & Adding new data to it
- Reading the File
students = open("student2.csv","w")
- using \n for adding to a new line
students.write("\n1, will, 29 , male")
students.close()
- Checking if new data is added
students = open("student2.csv","r")
print(students.read())
students.close()
- using \n for adding to a new line
with open("student4.csv", "w") as students:
student = students.write("\n6, rose, 29 , female")
print(student)
with open("student4.csv", "r") as students:
for student in students:
print(student)