Python 3.x Python将字符串与具有转义字符的字符串变量连接起来

Python 3.x Python将字符串与具有转义字符的字符串变量连接起来,python-3.x,scripting,Python 3.x,Scripting,我有一个python脚本命令,如下所示: start_command = [ "load=" + location + "/lib/abc " + "conf=myconf " + location + "/bin/mysqld " "--defaults-file=" + location + "/var/myfile.cnf "

我有一个python脚本命令,如下所示:

start_command = [
        "load=" + location + "/lib/abc " + "conf=myconf " +
        location + "/bin/mysqld "
        "--defaults-file=" + location + "/var/myfile.cnf " 
        ]

    
我想将代码的第二部分作为变量(connect_str)推送&在start命令中连接。但它不起作用。这是因为逃避角色吗

 connect_str="conf=myconf " +
        location + "/bin/mysqld "
        "--defaults-file=" + location + "/var/myfile.cnf "
 start_command = [
        "load=" + location + "/lib/abc " + connect_str

我的错误是声明了我更改过的字符串变量&使其工作。这实际上是注释问题,因为放入了多行

connect_str="conf=myconf " + location + "/bin/mysqld " "--defaults-file=" + location + "/var/myfile.cnf "
 start_command = [
        "load=" + location + "/lib/abc " + connect_str
          ]

有没有更好的方法来解决这个问题,而不是把它放在一行中?

我的错误是声明了我更改过的字符串变量并使它工作。这实际上是注释问题,因为放入了多行

connect_str="conf=myconf " + location + "/bin/mysqld " "--defaults-file=" + location + "/var/myfile.cnf "
 start_command = [
        "load=" + location + "/lib/abc " + connect_str
          ]

有没有更好的方法来解决这个问题,而不是把它放在一行中?

如果你想连接str,它应该是str,我在你的代码中看到一个列表,在你的there are/中没有转义符this\这个。我建议您使用这样的格式更好

connect_str="conf=myconf {} /bin/mysqld --defaults-file={} /var/myfile.cnf ".format(location,location)

如果你想连接str,它应该是str,我在你的代码中看到一个列表,在你的therears/中没有转义字符this\。我建议您使用这样的格式更好

connect_str="conf=myconf {} /bin/mysqld --defaults-file={} /var/myfile.cnf ".format(location,location)

是,使用\进行scape\n

connect_str = "conf=myconf " + location + \
    " /bin/mysqld " "--defaults-file=" + location + \
    " /var/myfile.cnf "

是,使用\进行scape\n

connect_str = "conf=myconf " + location + \
    " /bin/mysqld " "--defaults-file=" + location + \
    " /var/myfile.cnf "