【问题标题】:copy 1 file to multiple with names and input from another file将一个文件复制到多个名称并从另一个文件输入
【发布时间】:2015-05-09 19:01:25
【问题描述】:

我想阅读包含 40/50 个名称并拥有 ECT.docx 的 names.txt

想要将 ECT.docx 复制到 name.txt 中的多个名称。

我在 Python 中做了以下命令,请纠正它不工作。

import os
file=open('names.txt')
for nam in file.readlines():
    cmd='copy ECT.docx ' + nam +'.doc'

【问题讨论】:

标签: python operating-system command


【解决方案1】:

我只会使用带有 w+ 的 python 写入文件,但我在您的偏好中提供了示例。我使用 With 块来处理关闭文件。

import os
import subprocess
with open("names.txt") as f:
    for nam in f.readlines():
        myCmd='cmd /c copy ECT.docx ' + nam +'.doc'
        subprocess.call(myCmd)

【讨论】:

    猜你喜欢
    • 2014-12-20
    • 2014-10-06
    • 1970-01-01
    • 2017-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多