擅长:python、mysql、java
<p>如果你坚持<code>os.system</code>,你想要<a href="https://docs.python.org/3/library/shlex.html?highlight=quote#shlex.quote" rel="nofollow noreferrer">^{<cd2>}</a>:</p>
<blockquote>
<p>Return a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line, for cases where you cannot use a list.</p>
</blockquote>
<p>也就是说,我强烈建议移到<a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow noreferrer">the ^{<cd3>} module</a>(<code>subprocess.call</code>将是这里<code>os.system</code>的最简单替代,尽管还有其他选项),并以列表形式传递参数,允许<code>subprocess</code>进行转义(在Windows上必要时),消除手动添加引号的需要,避免完全在Windows上进行字符串处理其他操作系统(它可以直接<code>exec</code>参数向量,不需要转义)。你知道吗</p>