Answers for "how to print a random line from a text file in python"

0

get random line from file python

import random
lines = open('file.txt').read().splitlines() # creates a list with one line per iteù
randomLine =random.choice(lines) # pick up a random item in this list
Posted by: Guest on May-09-2021

Code answers related to "how to print a random line from a text file in python"

Python Answers by Framework

Browse Popular Code Answers by Language