简体   繁体   English

如何使用python在yaml文件中自动创建子文件夹或立即文件?

[英]How to automatically create sub-folder or immediate files in yaml file with python?

I am writing a python code to do the machine learning problem by reading an arff file. 我正在编写一个python代码,通过阅读arff文件来解决机器学习问题。 Meanwhile, I want to create a yaml file to record each step of data generation process. 同时,我想创建一个Yaml文件来记录数据生成过程的每个步骤。 The format is like this: 格式如下:

Round1: 第1轮:

-exe /exes/method
-parameters -a 1 -b 2
-input /data/loop1/data.arff
-output /data/loop1/train1.arff, /data/loop1/test1.arff

Round2: Round2:

-exe /exes/method
-parameters -a 1 -b 2
-input /data/loop2/data.arff
-output /data/loop2/train2.arff, /data/loop2/test1.arff

Round n: 回合n:

... ...

The /data/loop1 or data/loop2 is the subfolder I want to generate automatically through the program. /data/loop1data/loop2是我想通过程序自动生成的子文件夹。 And I want to save the result arff file into the folder. 我想将结果arff文件保存到该文件夹​​中。

Does anyone know how to write it? 有人知道怎么写吗?

For making output directory, try: 要创建输出目录,请尝试:

import os
os.makedirs("path/to/out/dir")

For writing yaml file 用于编写yaml文件

import os
import yaml
strOutFile = os.path.join("path/to/out/dir", "out.yaml")
objFile = open(strOutFile, "w")
objFile.write(yaml.dump(yourObject))
objFile.close()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将子文件夹中的文件作为参数传递给python中的函数 - How to pass a file in sub-folder as parameter to a function in python 如何在不复制python中的文件夹结构的同时从文件夹(包括子文件夹)复制所有文件 - How to copy all files from a folder (including sub-folder) while not copying the folder structure in python 如何从另一个文件夹和子文件夹导入python文件 - How to import python-file from another folder and sub-folder 如何进行递归子文件夹搜索并返回列表中的文件? - How to do a recursive sub-folder search and return files in a list? 如何在pycharm的另一个子文件夹中设置数据文件的python搜索目录? - How to set the python searching directory of data file in another sub-folder in pycharm? 如何在不指定子文件夹名称的情况下自动合并来自多个子文件夹的多个 CSV? - How to automatically merge multiple CSVs from multiple sub-folders, without specifying sub-folder name? python导入的子文件夹名称相同 - Same sub-folder names for python imports 从python中的子文件夹层次结构导入 - Importing from sub-folder hierarchy in python 从本地子文件夹导入文件 - Importing file from local sub-folder 遍历文件夹结构,重命名文件以匹配子文件夹,保留文件扩展名 - Walk a folder structure, rename files to match sub-folder, keep file extension
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM