lundi 25 juillet 2016

Show only one word out of a random list of lines? [on hold]

def random(self): # Generator-knapptryck
    import tkinter
    with open('dishes.txt') as f:
        resultat = random.sample([i.strip() for i in f], 7)
    tkinter.messagebox.showinfo("Meny", "Veckomeny:\n %s" % resultat)
    f.close()

This is my code for a random seven meals. I have created lines of meals in a txt with groceries that is needed. Ex: "Lasagne, Minced meat, Tomatosaus,... etc"

I would like the result to only include the first word in each line. (First word is the name of the meal). I tried the split function but got some errors, Im quite new to this..




Aucun commentaire:

Enregistrer un commentaire