擅长:python、mysql、java
<p>另一种方式:</p>
<pre><code>import itertools
import string
variations = itertools.permutations(string.printable, 1)
text_file = open("Output.txt", "w")
for v in variations:
text_file.write(f"{v[0]}\n")
text_file.close()
</code></pre>
<p>如上所述,有更好的方法。每次迭代都要打开文件,只打开一次。v是一个元组<code>('1',)</code>等,因此需要索引第一个元素</p>