我需要我的脚本循环遍历3个相应的数组

时间:2017-07-05 23:19:20

标签: python

好的,这需要一点点解释......

我正在制作一个带有praw的reddit bot,我正在存储主题,主题描述以及通过数组在变量中提交top的用户。

每周,机器人都会发布一个新的reddit线程,该线程应包含1个主题,以及它的相应描述和提交者。

我需要脚本做的是循环遍历数组而不重复任何数据,这样我就不会重复发帖。

机器人将在每周运行它的调度程序上,这是让我失望的部分,因为正常的方法不会永久清除选项。

最理想的情况是,我希望将代码存储在另一个变量中,用于我可用于放入预设消息的每种数据类型

这里是变量:

#Question Databank
challengeTopicData = ('Command line', 'Choose your own theme', 'Memes', 'Glitch','No app drawer','Not minimal')
challengeDescriptionData = ('The best command-line/vintage computer theme','Choose a theme from given pool of choices and they will have to stick to it completely.','Make a theme from a meme. It\'s literally wide open - make the crappiest, low effort theme you can for 1 week only','Create a theme based around a glitch effect, whether it be the wallpaper, widget, or both','In this challenge you must create a homescreen with all of your icons on it, and show off your homescreen organization skills','Literally anything that can\'t be considered minimal')
challengeSubmitterData = ('-Tilde','thetinygoat','SuperScientistOfDoom','hallowaslosdu','inaforestgump','ssyynnxx')

1 个答案:

答案 0 :(得分:0)

根据这些方面的一些事情,您可以根据需要将数据更改为dicts或元组。

def example():
    f1 = open("count.txt","r+")
    index = int(f1.read())
    data = [{'topic':'random topic 1', 'description':'random description 1', 'user': 'random user 1'}, {'topic':'random topic 2', 'description':'random description 2', 'user': 'random user 2'}]

    f1.seek(0,0)
    f1.write("%s" % index+1)
    f1.close()
    return data[index]