Here's the answer in a generalized form:
f = open("path/to/file", "r") # opens the file as read-only
content = f.read() # there are easier ways to do this, but....
### do whatever you're doing here....
f.close() # MAKE SURE YOU CLOSE FILES when you're done with them
# if you don't, you're asking for memory leaks.
You can also use a context manager, but it's slightly harder to read:
with open("path/to/file","r") as f:
content = f.read() # again, this is not the BEST way....
### do stuff with your file
# it closes automatically, no need to call f.close()
Outside of file operations, here's string -> list stuff:
"a,b,c,d,e,f,g".split(',')
-> ['a','b','c','d','e','f','g']
# str.split creates a list from a string, splitting elements on
# whatever character you pass it.
And here's random.choice
:
import random
random.choice(['a','b','c','d','e','f','g'])
-> 'c' # chosen by fair dice roll, guaranteed to be random! ;)
# random.choice returns a random element from the list you pass it