<p><a href="https://www.python.org/dev/peps/pep-0008/#maximum-line-length" rel="nofollow">PEP 0008 does say it's ok</a>对<code>with</code>行使用反斜杠。你知道吗</p>
<blockquote>
<p>Backslashes may still be appropriate at times. For example, long, multiple with -statements cannot use implicit continuation, so backslashes are acceptable.</p>
</blockquote>
<p>虽然建议缩进,但行应该是这样的:</p>
<pre><code>with tempfile.NamedTemporaryFile(prefix='malt_input.conll.',
dir=self.working_dir, mode='w', delete=False) as input_file, \
tempfile.NamedTemporaryFile(prefix='malt_output.conll.',
dir=self.working_dir, mode='w', delete=False) as output_file:
pass
</code></pre>
<p>建议您将它缩进到下面的代码块中一个明显不同的空间量,这样可以更清楚地看到with行的结束和块的开始。你知道吗</p>
<p>但是,如果将参数括在括号中,则实际上不需要使用斜杠</p>
<pre><code>with (tempfile.NamedTemporaryFile(prefix='malt_input.conll.',
dir=self.working_dir, mode='w', delete=False)) as input_file, (
tempfile.NamedTemporaryFile(prefix='malt_output.conll.',
dir=self.working_dir, mode='w', delete=False)) as output_file:
pass
</code></pre>
<p>当然,这取决于你准确的句子安排,你的里程数可能会因在一行末尾加括号是否比反斜杠好而有所不同。你知道吗</p>