mahmood
mahmood

Reputation: 24795

concatenating string in python

I am converting a command line to a python string. The command line is:

../src/clus -INFILE=../input/tua40.sq -OUTPUT=OUT

The python statement is:

c_dir = '~/prj/clus/'
c_bin = c_dir + 'src/clus'
c_data = c_dir + 'input/tua40.sq'

c = LiveProcess()
c.executable = c_bin
c.cwd = c_dir 
c.cmd = [c.executable] + ['-INFILE=', 'c_data, '-OUTPUT=OUT'] 

Problem is the c.cmd at the end looks like

~/prj/clus/src/clus -INFILE= ~/prj/clus/input/tua40.sq ...

Not that there is a 'space' after '=' which causes the program to report an error.

How can I concatenate '=' to the path?

Upvotes: 0

Views: 509

Answers (4)

user130076
user130076

Reputation:

Try this:

c.cmd = [c.executable] + ['-INFILE='+c_data, '-OUTPUT=OUT']

Upvotes: 0

Ned Batchelder
Ned Batchelder

Reputation: 376012

LiveProcess is expecting an argv-style list of arguments. Where you want to make one argument, you need to provide one string. So use concatenation to make the string:

c.cmd = [c.executable] + ['-INFILE='+c_data, '-OUTPUT=OUT'] 

Also, no need for the list addition:

c.cmd = [c.executable, '-INFILE='+c_data, '-OUTPUT=OUT'] 

Upvotes: 6

Daenyth
Daenyth

Reputation: 37461

Given that it looks like you're concatenating paths, you should be using os.path.join, not regular string concat.

Upvotes: 0

Alpha01
Alpha01

Reputation: 856

Why don't you just concatenate string like this:

a = 'A'+'B'

then

a == 'AB'

that is in your example

['-INFILE=' + c_data, '-OUTPUT=OUT'] 

Upvotes: 0

Related Questions