我们可以在python的os.system()中使用\作为转义序列吗
我的代码是我们可以在python的os.system()中使用\作为转义序列吗,python,Python,我的代码是 File "./e1.py", line 4 os.system("mysqld_safe -u root -proot -e 'update mysql.user set password=PASSWORD(%s) where User="root"'" %rootpassword)
File "./e1.py", line 4
os.system("mysqld_safe -u root -proot -e 'update mysql.user set password=PASSWORD(%s) where User="root"'" %rootpassword)
^
SyntaxError: invalid syntax
绝对
在你的情况下,你会这样做
system("mysqld_safe -u root -proot -e 'update mysql.user set password=PASSWORD(%s) where User=\"root\"'" % rootpassword)
其中\“被视为字符串的一部分,而不是字符串的封闭部分。该字符串中没有反斜杠…\“尝试使用它,为什么不试试呢?