【问题标题】:how to write one word in one line python3 [duplicate]如何在一行python3中写一个单词[重复]
【发布时间】:2018-04-02 15:45:42
【问题描述】:

我用writelines([name])尝试过。但是它写的单词没有任何空格,并且一个接一个。这是我的代码:`

 import time 
 from time import sleep
 import random 
 import secrets
 import string
 from threading import Thread


 def run_bot():
     x1 = random.choice(string.ascii_uppercase)
     x2 = random.choice(string.ascii_lowercase)
     x3 = random.choice(string.ascii_lowercase)
     x4 = random.choice(string.ascii_lowercase)
     x5 = random.choice(string.ascii_lowercase)
     name = str(x1 + x2 + x3 +x4 +x5)
     print(name)
     f = open('names.txt', 'a')
     f2 = open('namero.txt', 'a')
    f2.writelines([name])

while  True:
    for i in range(5):
        run_bot()    

`

【问题讨论】:

    标签: python file loops rows writing


    【解决方案1】:

    您需要手动插入新行。应该这样做:

    print(name + ‘\n’)
    

    我主要使用 JavaScript,但在 Python 方面有一些经验。让我知道它是否有效。

    【讨论】:

    • 嗯是的忘记了xd。据我所知,我认为这对我有用 thx btw
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2022-01-19
    • 2015-10-27
    • 1970-01-01
    相关资源
    最近更新 更多