1

How do i create a csv file that creates a duplicate file like csv2kml(1), csv2kml(2), if the file already exists?

Right now it overrides everytime I execute it. I tried a, a+ but im confused. Please help. Thanks.

from datetime import datetime
import os
import pandas as pd

data_df = pd.read_csv('21090700.CSV')

dir = r"C:mypath"
filepath = os.path.join(dir, "csv2kml.kml")
with open(filepath, 'a+') as f:
    f.write("<?xml version='1.0' encoding='UTF-8'?>\n")
    f.write("<kml xmlns='http://earth.google.com/kml/2.1'>\n")
    f.write("<Document>\n")
    f.write("   <name>csv2kml.kml</name>\n")
Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
Mega_maha
  • 17
  • 4

0 Answers0