【问题标题】:How to submit different scripts to the command line in python -如何在python中向命令行提交不同的脚本-
【发布时间】:2011-08-27 21:19:22
【问题描述】:

我正在尝试循环并将 shell 脚本提交到 python 中的命令行。虽然这适用于给定文件:

os.system('qsub /directory/filename')

这不是:

file = '/directory/filename'
os.system('qsub file')

Python 正在解释单词“文件”而不是目标文件。我怎样才能解决这个问题?

【问题讨论】:

    标签: python shell command-line


    【解决方案1】:

    试试这个:

    file = '/directory/filename'
    os.system('qsub %s' % file)
    

    您必须将“文件”作为参数传递。

    请参阅http://diveintopython.net/native_data_types/formatting_strings.html 获取一些示例或查看http://docs.python.org/library/stdtypes.html#string-formatting 获取官方文档。

    【讨论】:

      【解决方案2】:

      'qsub 文件'是一个字符串使用'qsub' + 文件

      【讨论】:

        【解决方案3】:

        用途:

        os.system('qsub %s' % file)
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-09-24
          • 1970-01-01
          • 2020-05-02
          • 1970-01-01
          • 2017-02-14
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多