我有一段python代码,它应该打开(或创建)一个CSV文件,并在它的末尾追加一个新行。但是,在每个条目之间添加了一个额外的空行。有没有办法避免这种情况?在
我有大约500个脚本实例,它们都访问同一个文件,尽管(理论上)它们应该在不同的时间访问该文件。在
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()
“b”选项为我提供了窍门,请检查API文档:https://docs.python.org/2/library/functions.html?highlight=open#open
通过评论回答问题。问题是使用
wb
模式而不是ab
模式。在相关问题 更多 >
编程相关推荐