[英]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/loop1
或data/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.