I have a piece of python code which is supposed to open (or create) a CSV file and append a new row to the end of it. However, there is an extra blank line added between each entry. Is there a way to avoid this?
I have around 500 instances of the script which all access the same file, though (in theory) they should access the file at different times.
def writeBest(fileName, savePath, data):
# Create a filename
name = "BEST_" + fileName + ".csv"
# Create the complete filename including the absolute path
completePath = os.path.join(savePath, fileName)
# Check if directory exists
if not os.path.exists(completePath):
os.makedirs(completePath)
completeName = os.path.join(completePath, name)
# Write the data to a file
theFile = open(completeName, 'wb')
writer = csv.writer(theFile, quoting=csv.QUOTE_ALL)
writer.writerow(data)
# Close the file
theFile.close()
ab
mode, notwb
. – Holloway'a'
mode will create the file if it doesn't exist. (Test it yourself.) Anyway, can you show us a same of yourdata
argument? – 2rs2ts