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 :: how to display text on boxplot in python 
Python :: removing an item from a list and adding it to another list python 
Python :: python numpy read from stdin 
Python :: assert_series_equal 
Python :: python site-packages pyspark 
Python :: jupyter notebook file not opening about::blank 
Python :: Only show legend of inner donut 
Python :: python import cache (testing grepper, maybe not a helpful solution) 
Python :: Improve the Request Add Timeout to request 
Python :: python for schleife 
Python :: py random sample 
Python :: how print python 
Python :: what does bin do in python 
Python :: how can you make a data fram 
Python :: scraped text in Russian encoding python 
Python :: how to save text file content to variable python 
Python :: to remove whitspace in string 
Python :: python list as stacks 
Python :: convert depth image to point cloud 
Python :: create layer file arcpy 
Python :: unittest only run test if other tests passes 
Python :: traint test split on column id 
Python :: Read a string with digits from the input and convert each number to an integer. Create a list in which you should include only odd digits. 
Python :: read sharepoint list using python 
Python :: how to import modules from upper or previous dir in py 
Python :: How to draw a Ninja Design using python turtle 
Python :: python detect ranges in list 
Python :: plt.text background alpha 
Python :: if user_answer==answer: ecpeted index erroe pythin fx 
Python :: python change type of every element in a dictionary 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =