Answers for "read random line from file 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
0

Python program to read a random line from a file

import random
def randnum(fname):
	with open(fname).read().splitlines() as
	print(lines)
	return random.choice(lines)

print(randnum('file1.txt'))
Posted by: Guest on December-03-2020
0

Python program to read a random line from a file.

import random
def randnum(fname):
	lines=open(fname).read().splitlines()
	print(lines)
	return random.choice(lines)

print(randnum('file1.txt'))
Posted by: Guest on December-03-2020

Code answers related to "read random line from file python"

Python Answers by Framework

Browse Popular Code Answers by Language