mahmood
mahmood

Reputation: 24695

python print a string in array format

I passed an argument to a python script like -b bench. The bench is created like this:

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]

The bench.cmd should looks like:

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

to do that, I use print bench.cmd but it doesn't show the above statment correctly. Instead it shows:

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

how can I fix that?

Upvotes: 2

Views: 1320

Answers (4)

RanRag
RanRag

Reputation: 49547

Are you looking for this,

>>> 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'

or just concatenate your strings

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

Upvotes: 0

gefei
gefei

Reputation: 19766

case for join: ' '.join(bench.cmd)

Upvotes: 0

Wesley
Wesley

Reputation: 2264

Try: print ' '.join(bench.cmd). This joins the list and uses a space as delimiter

Upvotes: 3

ezod
ezod

Reputation: 7411

You could do ' '.join(bench.cmd).

Upvotes: 2

Related Questions