vendredi 24 avril 2015

Python Get Multiple Random Lines From File

Can some one help me with this real quick? Here is my code I am using:

# Lists:
anchorslist = []

#Files:
anchors = open(basepath + "anchors.txt", "r")

#Placed In List:
for line in anchors:
        anchorslist.append(line.replace("\n", "|"))

#Used:
type(anchorslist)

It will return a random line from my text file. What I want to achieve is getting let's say 10 random lines returned like this:

random_anchor1|random_anchor2|random_anchor3|random_anchor4

How would I modify the code to return that? Thanks.




Aucun commentaire:

Enregistrer un commentaire