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 :: if file exists delete python 
Python :: django template tag to display current year 
Python :: how to change django admin text 
Python :: pandas save file to pickle 
Python :: matplotlib is required for plotting when the default backend "matplotlib" is selected. 
Python :: converting string to datetime pandas 
Python :: how to iterate through files in a folder python 
Python :: python currnent time 
Python :: why is python hard 
Python :: change django admin title 
Python :: python get current directory 
Python :: how to get the calendar of current month in python 
Python :: python reload lib jupyter notebook %reload 
Python :: items of a list not in another list python 
Python :: scikit learn dataset into pandas dataframe 
Python :: python list all csv in dir 
Python :: tensorflow version check 
Python :: python print exception message and stack trace 
Python :: spark df shape 
Python :: incognito in selenium 
Python :: python toast notification 
Python :: python list of all states 
Python :: matplotlib log 
Python :: pandas dropna specific column 
Python :: python reload function in shell 
Python :: view whole dataset in python 
Python :: save request response json to file python 
Python :: how to check if column has na python 
Python :: pytube urllib.error.HTTPError: HTTP Error 410: Gone 
Python :: read csv as list python 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =