get random line from file python

Solutions on MaxInterview for get random line from file python by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "get random line from file python"
Giulia
10 Jan 2018
1import random
2lines = open('file.txt').read().splitlines() # creates a list with one line per iteรน
3randomLine =random.choice(lines) # pick up a random item in this list