python - 如何指定CSV保存在python中的路径
问题描述
默认路径似乎是我正在使用的项目文件夹,但我找不到任何文档来说明如何指定 csv 在机器上的保存位置,我目前正在使用 shutil 将文件移动到我想要的路径但是这个不是一个强大的解决方案,因为此应用程序将被许多用户使用,这可能会导致问题。
length = len(list1)
#convert job name to csv name
jobname = jobname + ".csv"
with open (jobname, 'w', newline='') as f:
thewriter = csv.writer(f)
thewriter.writerow(column_header_list)
i = 0
for x in range(length):
thewriter.writerow([list1[i],0,0,0,0,0,0,0,0,0,0])
i += 1
#create a path for the newly made file
original_path = r'C:\Users\Scott\OneDrive\Documents\DL\Main Application MRL'
original_path = (original_path + '\\') #concat to add backslash to path
original_path = original_path + jobname #add jobname to path
target_path = r'C:\Users\Scott\OneDrive\Documents\DL\JobData'
shutil.move(original_path,target_path)
解决方案
推荐阅读
- django - 在 django 命令中调用自己的 API 端点
- swiftui - 在 SwiftUI 中为 UITextView 设置初始视图偏移量
- javascript - 如何将列表映射到一定数量的数据
- java - 无法在空对象上调用方法 head()
- r - 如何在 pheatmap 中按行绘制值?
- javascript - 如何编辑模态图像(灯箱)以完全响应
- scala - 如何将返回的查询结果从 Salesforce SOAP API 转换为 Spark Dataframe
- python - 类内的函数未执行
- javascript - 有没有办法检查用户访问的下一个 URL?
- python - Geopandas:如何绘制国家/城市?