lundi 5 juin 2017

How would I pick a random item in a list that's in a text file? [duplicate]

This question already has an answer here:

Inside messages.txt is a list ['test','yes','im new to python']

import random

chatMessages = open('messages.txt', 'r')

print(random.choice(chatMessages))

I want to pick a random item in the list from messages.txt and print it out.




Aucun commentaire:

Enregistrer un commentaire