我创建了一个 python 脚本来输出 AAAA-ZZZZ 等的每 1-4 个字符的字母组合。
它工作得很好,但是我只需要在打印变量的末尾插入换行符,因为我将其用作要在另一个脚本中使用的单词列表。
我尝试同时使用 \r 和 \n,但是使用 \n 在末尾插入回车符和换行符(例如 AAAA CR LF),使用 \r 仅插入回车符(例如 AAAA CR)。
我的问题是是否可以在末尾插入换行符,或者由于 python 的限制这是不可能的?我尝试过使用记事本手动替换每个字符,这有效,但这只是解决问题并且使用起来不切实际。
非常感谢您的帮助!
import string
alpha = string.ascii_uppercase
w=(a+b+c+d for a in alpha for b in alpha for c in alpha for d in alpha)
x=(a+b+c for a in alpha for b in alpha for c in alpha)
y=(a+b for a in alpha for b in alpha)
z=(a for a in alpha )
with open("Output.txt", "w") as text_file: …Run Code Online (Sandbox Code Playgroud)