python以数组格式打印一个字符串

时间:2012-02-03 14:25:20

标签: python arrays string printing

我将参数传递给像-b bench这样的python脚本。 bench的创建方式如下:

bench_dir = '~/myFD/'
bench_bin = bench_dir + 'src/bin/Assembler'
bench_inp1 = bench_dir + 'input/in.fa'
bench_out1 = bench_dir + 'output/data.scratch'

bench= LiveProcess()
bench.executable = bench_bin
bench.cwd = bench_dir
bench.cmd = [bench.executable] + ['-s', bench_out1, '<', bench_inp1]

bench.cmd应如下所示:

~/myFD/src/bin/Assembler -s ~/myFD/output/data.scratch < ~/myFD/input/in.fa

要做到这一点,我使用print bench.cmd,但它没有正确显示上述声明。而是显示:

['~/myFD/src/bin/Assembler', '-s', '~/myFD/output/data.scratch', ' < ', '~/myFD/input/in.fa']

我该如何解决?

4 个答案:

答案 0 :(得分:3)

尝试:print ' '.join(bench.cmd)。这会加入列表并使用空格作为分隔符

答案 1 :(得分:2)

你可以' '.join(bench.cmd)

答案 2 :(得分:0)

你在找这个,

>>> mylist = ['~/myFD/src/bin/Assembler', '-s', '~/myFD/output/data.scratch', ' < ', '~/myFD/input/in.fa']
>>> " ".join(mylist)
'~/myFD/src/bin/Assembler -s ~/myFD/output/data.scratch  <  ~/myFD/input/in.fa'

或者只是连接你的字符串

bench.cmd = bench.executable + ' -s ' + bench_out1 + ' < ' + bench_inp1

答案 3 :(得分:0)

加入案例:' '.join(bench.cmd)