mercredi 18 mars 2015

How to read a text file by line in python

I want to randomly retrieve and print a whole line from a text file.


The text file is basically a list and so each item on that list needs to be searched.



import random

a= random.random

prefix = ["CYBER-", "up-", "down-", "joy-"]

suprafix = ["with", "in", "by", "who", "thus", "what"]

suffix = ["boy", "girl", "bread", "hippy", "box", "christ"]

print (random.choice(prefix), random.choice(suprafix), random.choice(prefix), random.choice(suffix))


this is my code for if i were to just manually input it into a list but i can't seem to find how to use an array or index to capture line by line the text and use that





Aucun commentaire:

Enregistrer un commentaire