用Shell脚本运行带命令行参数的Python程序

0 投票
1 回答
511 浏览
提问于 2025-04-16 13:50

我在一个文件夹里有一些文件,这些文件是我Python脚本的输入文件:

<1.in>
<1.in.xml>
<2.in>
<2.in.xml>
<3.in>
<3.in.xml>
...
..
.

到目前为止,我有以下内容:

for i in $(ls dir/*.in)
do
        new = ${i%%.in}
        test.py -i $new.in.xml -o out_$new -x $new.in -c 56
done

当我运行这个的时候,它没有生成一个输出文件(这个输出文件是通过-o选项定义的)。 出现的错误是:

IOError: [Errno 2] No such file or directory

有什么建议吗?

1 个回答

1

确保你是用 open(file_name, 'w') 这样的方式打开文件,这样才能创建文件。如果不这样做,文件就不会被创建。

撰写回答