I am trying to import a set of lists in python and call a random item from one of the lists
Question: 
    #Set of lists I want to import into my python program called "setlist.txt"
    ---------------------------------------------------------------------------------------------
    Tripolee = ('Saeed Younan', 'Matrixxman', 'Pete Tong', 'Dubfire', 'John Digweed', 'Carl Cox')
    Ranch = ('Dabin', 'Galantis', 'Borgeous', 'Shpongle', 'ODESZA', 'Kaskade')
    Sherwood = ('Nadus', 'Mr. Carmack', 'Wave Racer', 'Lido', 'Goldlink', 'Four Tet', 'Flume')
    Jubilee = ('Chaz French', 'MartyParty', 'Sango', 'Brodinski', 'Phutureprimitive', 'EOTO')
    The Hangar = ('Vourteque', 'The Gentlemen Callers', 'Bart&Baker', 'Jaga Jazzist', 'JPOD')
    Forest = ('Vibe Street', 'Lafa Taylor', 'Vaski', 'Little People', 'jackLNDN', 'MartyParty')
    ---------------------------------------------------------------------------------------------
    
    #program
    
    from sys import exit
    from random import randint
    from sys import argv
    
    script, setlist = argv
    
    setlist = open(setlist)
    
    print "Here is the setlist for day 1"
    print setlist.read()
    print "%r is playing on the Tripolee stage" % random.choice(setlist.readline(2))
    

I have a bunch more code in between all this that I"m not putting up here but
basically that last line what I'm having trouble with.


Answer: Probably not the best format for your file but you can split and use
ast.literal_eval:

    
    
    from ast import literal_eval
    with open("in.txt") as f:
        choices = [literal_eval(line.split(" = ")[-1]) for line in f]
    

Which will give you a list of tuples which you can pass to random.choice:

    
    
    [('Saeed Younan', 'Matrixxman', 'Pete Tong', 'Dubfire', 'John Digweed', 'Carl Cox'), ('Dabin', 'Galantis', 'Borgeous', 'Shpongle', 'ODESZA', 'Kaskade'), ('Nadus', 'Mr. Carmack', 'Wave Racer', 'Lido', 'Goldlink', 'Four Tet', 'Flume'), ('Chaz French', 'MartyParty', 'Sango', 'Brodinski', 'Phutureprimitive', 'EOTO'), ('Vourteque', 'The Gentlemen Callers', 'Bart&Baker', 'Jaga Jazzist', 'JPOD'), ('Vibe Street', 'Lafa Taylor', 'Vaski', 'Little People', 'jackLNDN', 'MartyParty')]
    

I have no idea where setlist is supposed to come from, you file is what looks
like tuple assignments. `setlist.readline(2)` would read 2 bytes or actually
in your case nothing as you have already exhausted the file iterator calling
`read`.

I would suggest after extracting using literal_eval putting your file in a
more usable format, maybe creating a dict using the name as the key and
dumping the dict.

    
    
    from ast import literal_eval
    with open("in.txt") as f:
        choices = {}
        for line in f:
            ven, tpl = line.split(" = ")
            choices[ven] = literal_eval(tpl)
        print(choices)
    

Output:

    
    
    {'Jubilee': ('Chaz French', 'MartyParty', 'Sango', 'Brodinski', 'Phutureprimitive', 'EOTO'), 'Tripolee': ('Saeed Younan', 'Matrixxman', 'Pete Tong', 'Dubfire', 'John Digweed', 'Carl Cox'), 'The Hangar': ('Vourteque', 'The Gentlemen Callers', 'Bart&Baker', 'Jaga Jazzist', 'JPOD'), 'Ranch': ('Dabin', 'Galantis', 'Borgeous', 'Shpongle', 'ODESZA', 'Kaskade'), 'Sherwood': ('Nadus', 'Mr. Carmack', 'Wave Racer', 'Lido', 'Goldlink', 'Four Tet', 'Flume'), 'Forest': ('Vibe Street', 'Lafa Taylor', 'Vaski', 'Little People', 'jackLNDN', 'MartyParty')}
    

You can persist the dict using `json.dump` or the `pickle` module so your data
will be in a lot easier format to each time.

To make it a little clearer what you have below is the content of your .txt
file:

    
    
    ---------------------------------------------------------------------------------------------
    Tripolee = ('Saeed Younan', 'Matrixxman', 'Pete Tong', 'Dubfire', 'John Digweed', 'Carl Cox')
    Ranch = ('Dabin', 'Galantis', 'Borgeous', 'Shpongle', 'ODESZA', 'Kaskade')
    Sherwood = ('Nadus', 'Mr. Carmack', 'Wave Racer', 'Lido', 'Goldlink', 'Four Tet', 'Flume')
    Jubilee = ('Chaz French', 'MartyParty', 'Sango', 'Brodinski', 'Phutureprimitive', 'EOTO')
    The Hangar = ('Vourteque', 'The Gentlemen Callers', 'Bart&Baker', 'Jaga Jazzist', 'JPOD')
    Forest = ('Vibe Street', 'Lafa Taylor', 'Vaski', 'Little People', 'jackLNDN', 'MartyParty')
    

To print the venue and set list you can use dict.items:

    
    
    for ven, set_l in choices.items():
        print("Set list for {}: {}".format(ven, ", ".join(set_l)))
    

Output:

    
    
    Set list for Jubilee:  Chaz French, MartyParty, Sango, Brodinski, Phutureprimitive, EOTO
    Set list for Tripolee:  Saeed Younan, Matrixxman, Pete Tong, Dubfire, John Digweed, Carl Cox
    Set list for The Hangar:  Vourteque, The Gentlemen Callers, Bart&Baker, Jaga Jazzist, JPOD
    Set list for Ranch:  Dabin, Galantis, Borgeous, Shpongle, ODESZA, Kaskade
    Set list for Sherwood:  Nadus, Mr. Carmack, Wave Racer, Lido, Goldlink, Four Tet, Flume
    Set list for Forest:  Vibe Street, Lafa Taylor, Vaski, Little People, jackLNDN, MartyParty
    

When you open the file and call `read` you now have all the content in your
file stored as a string. You then print the string, next you try
`random.choice(setlist.readline(2))`, `readline(2)` is trying to read two
bytes which it cannot even do as the file pointer is at the end of the file as
you have already called `read` so you see an empty string outputted.

If you want to get a random string from the first tuple:

    
    
    choices = [literal_eval(line.split(" = ")[-1]) for line in f]
    from random import choice
    print(choice(choices[0]))
    

