我能够编译代码,但找不到我的 csv 文件,因此我认为它没有生成。
该方法应创建并写入 csv 文件。我所知道的是它在哪里创建,以及如何定义它在工作时在哪里创建。
def generateCSVfile(fileName,fileDescription,fileLocation,md5Hash):
with open('deploymentTemplate.csv', 'w') as csvfile:
createRow = csv.writer(csvfile, delimiter=' ',
quotechar='|', quoting=csv.QUOTE_MINIMAL)
createRow.writerow([fileName,' ', fileDescription,' ', fileLocation,' ', md5Hash])
最佳答案
要查找 csv 文件的绝对路径(即文件系统中的保存位置),并检查其保存是否正确:
import os
print("Output is located at " + os.path.abspath('deploymentTemplate.csv'))
print("File exists? " + str(os.path.exists('deploymentTemplate.csv')))
可能的输出:
输出位于 C:\deploymentTemplate.csv
文件已存在?正确
关于python - 在 python 中创建并写入 CSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37330859/