Hi SO,
This is a kind of newbie question, but I couldn't find a solution. I read a list of strings from a file, and try to get a random, 5 element sample with random.sample, but the resultung list only contains characters. Why is that? How can I get a random sample list of strings?
This is what I do:
names = random.sample( open('names.txt').read(), 5 )
print names
This gives a five element character list like:
['\x91', 'h', 'l', 'n', 's']
If I omit the random.sample part, and print the list, it prints out every line of the file, which is the expected behaviour, and proves that the file is read OK.