I am trying to convert the table created using the PrettyTable to CSV format using Python in an AWS lambda function. I am able to generate the CSV file, but the content inside the CSV file is not in CSV format. How can I fix if there is any issue in the code?
import os
import json
from prettytable import PrettyTable
data = PrettyTable(["Col1", "Col2", "Col3"])
data.add_row(["test1", "test2", "test3"])
data.add_row(["test4", "test5", "test6"])
data.add_row(["test7", "test8", "test9"])
print(data)
data_string = data.get_string()
with open('/tmp/test.csv', w) as f:
f.write(data_string)
f.close
The data content inside the CSV file is printing in the same way as in the terminal. Could anyone help me to fix the issue?