如何在 Python 中读取多行输入?

用户11778225

Python 3.6.8 - 空闲

我正在尝试允许使用链接进行复制和粘贴输入。作为参考,如果有帮助,我正在使用 Spotify 播放列表链接。

我想要做的是:将链接复制并粘贴到这个小程序中,然后对所有链接进行随机播放。有没有办法读\n入输入,或者只是检查空格/多输入?

import random

inputlinks = input("Paste your links: ")
links = inputlinks.replace(" ", "").replace("https://"," httpshhttps://").split("httpsh")
blanklist = []

def randomizer():
    global blanklist
    while len(links) > 0:
        indexed = links[random.randint(0,len(links)-1)]
        blanklist.append(indexed)
        links.remove(indexed)
    blanklist = str(blanklist)
    blanklist = blanklist.replace("'", "").replace(" , ", " ").replace("[","").replace("]","")
    with open("shuffled.txt", "w") as saving:
        saving.write(blanklist)

randomizer()
Jeff Huang

以下将接受输入,将每一行附加到 inputLinks 数组,直到出现空行。要输入,只需粘贴所有链接,每行一个,最后一行为空。

inputLinks = []
nextLink = input()
while len(nextLink) > 0:
    inputLinks.append(nextLink)
    nextLink = input()

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章