【发布时间】:2015-07-07 20:04:22
【问题描述】:
我有一个包含以下代码的 Bash 脚本:
merge_ROOT_files(){
output_file=""$(date -u "+%Y-%m-%dT%H%M%S")"Z_merged.root"
list_of_files="$(find . -name \*.root -type f)"
command="hadd "${output_file}""
for current_file in ${list_of_files}; do
echo "found ROOT file "${current_file}""
command=""${command}" "${current_file}""
done
echo "merge ROOT files to output ROOT file "${output_file}""
echo "merge command: ${command}"
eval "${command}"
}
merge_ROOT_files
您可以看到它递归搜索以.root 结尾的文件,然后循环遍历这些文件。我怎么能在 Python 中做类似的事情?我可以想象生成一个包含完整或相对路径的各种找到文件的列表,然后循环遍历该列表,但我不确定如何生成这样的列表。
【问题讨论】:
-
您为每个答案发布的反馈是出色的提问者的原因。在 SO 中很少见。