Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get random line from file python

import random
lines = open('file.txt').read().splitlines() # creates a list with one line per item
randomLine =random.choice(lines) # pick up a random item in this list
Comment

PREVIOUS NEXT
Code Example
Python :: 12 month movinf average in python for dataframe 
Python :: import pyx file 
Python :: stock market python 
Python :: python unittest multiple test cases 
Python :: boder color in tkinter 
Python :: get_or_create in django 
Python :: creating python classes 
Python :: change folder icon with python 
Python :: python class set dict method 
Python :: python pytest no coverage on failure 
Python :: python get element by index 
Python :: how to input a picture into opencv raspberry pi 
Python :: .add_prefix to certain columns python 
Python :: como poner estado a un bot en discord 
Python :: split string by special characters python 
Python :: pandas index append value 
Python :: how to define number in python 
Python :: how to get last dimension of an array python 
Python :: webpage with aiohttp 
Python :: get resolution of image python 
Python :: customise the django rest api view 
Python :: importing logistic regression 
Python :: python count elements in sublists 
Python :: python with example 
Python :: how to sort a list 
Python :: insert function in list 
Python :: calendar library in python 
Python :: gcd python 
Python :: pytest fixtures scope explained 
Python :: update python 2 to 3 
ADD CONTENT
Topic
Content
Source link
Name
7+2 =