擅长:python、mysql、java
<p>您可以将<a href="https://docs.python.org/3/library/functions.html#iter" rel="nofollow noreferrer">^{<cd1>}</a>函数与<code>stop</code>哨兵一起使用,然后将生成的序列字符串与<code>'\n'</code>连接起来输出:</p>
<pre><code>with open('randomfile', 'w') as f:
f.write('\n'.join(iter(input, 'stop')))
</code></pre>