如何在python中使用字符串格式化bash命令而不调用NoneType?

时间:2016-01-23 15:29:03

标签: python bash types terminal formatting

我不久前创建了一个滑动窗口程序,我正在尝试使用bash命令。

我需要稍后使用bash命令使用多个程序,因此使用bash是必要的。

我创建了一个连接配对命令的master_function。

所以命令以bash的形式输入:

python swindow.py sliding_window window,interval,second_window path/window{0},5,path/window{1}

并且Python应该像这样解释它:

python swindow.py sliding_window -window path/window{0} -interval 5 -path/window{1}

我希望{0}和{1}用作窗口编号的int {即window0,window 1等)所以我用.format(x,x)来指定窗口编号。

以下是将{0}和{1}更改为整数的功能。 当我尝试使用此函数时,它返回错误

AttributeError: 'NoneType' object has no attribute 'format'

如何解决此问题?我尝试使用enter image description here,使用%i代替.format,以及其他一些技术,但都没有用。

def master_function():
    program = sys.argv[1]
    arguments_list = sys.argv[2].split(",")
    arguments_values_list = sys.argv[3].split(",")
    argument_value_pairs_list = zip(arguments_list, arguments_values_list)

    com = program + "".join(" -" + arg_pair[0] + " -" + arg_pair[1] for arg_pair in argument_value_pairs_list) 
    x = 0

    return com.format(0,0)

0 个答案:

没有答案