The
evenements.txt
has a total of 160 lines. I wont go into too many details as i want to be able to learn the rest of the code by myself. But when i run this code using the
for loop in liste_evenement
, i believe it only returns the last line of the
evenements.txt
instead of all lines. What am i missing? The code is supossed to return a list of events separated in different lists. So there are lists in my list and im using the .split to separate the element in my lists(this is related to my evaluation but this isnt about my question, i am just giving you guys some background). But my actual question here is about the problem when i print my
words
which is not returning the whole file.
with open("evenements.txt", "r", encoding="utf-8-sig") as evenement:
liste_evenement = evenement.readlines()
words = []
for line in liste_evenement:
words = line.split(" ")
print(words)
Code has to return :
[['Danse', 'Samedi de danser...', 202, 202],
['Musique', 'Peter Gunn : spécial rétro francophone', 203, 205],
['Musique', 'Eletric Power Trio', 212, 212],
['Théâtre', 'Hamlet', 212, 212]]
its french, but you get the picture. so every lists of my global list is an event. And so far its only returning :
['Musique/Festival', 'OFF', 'de', 'Québec/2018-07-04/2018-07-08']
I believe this is the last line of file that has a total of 160 lines as mentionned. Now if you could also help me remove those
'/'
in the code, thatd be great. Because im having a hard time manipulating list. Thank you !
EDIT : I managed to put them all in different lists but im having trouble adding them all to another list and im also having trouble removing the
'\n'
Updated code :
with open("evenements.txt", "r", encoding="utf-8-sig") as evenement:
liste_evenement = evenement.readlines()
words = []
for line in liste_evenement:
words = line.split("/")
print(words)
Heres what its returning right now :
['Musique', 'Shawn Phillips', '2018-08-24', '2018-08-24\n']
['Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25\n']'['Musique', 'Perséides musicales', '2018-08-03', '2018-08-03\n']
['Musique', 'Gaétan Leclerc chante Félix et…', '2018-08-17', '2018-08-17\n']
['Musique', 'The Ring of Fire : a Johnny Cash Experience', '2018-07-21', '2018-07-21\n']
['Musique', "Jazz'Art", '2018-07-27', '2018-07-29\n']
['Musique', 'Génération Crooners', '2018-07-07', '2018-07-07\n']
['Musique', 'Fiesta Latina avec Me llamo Son', '2018-07-14', '2018-07-14\n']
['Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25\n']
['Musique', 'Concert au jardin', '2018-07-04', '2018-07-04\n']
['Musique', 'Concert au jardin', '2018-07-11', '2018-07-11\n']
And i want it to return :
[['Musique', 'Shawn Phillips', '2018-08-24', '2018-08-24]
['Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25]
['Musique', 'Perséides musicales', '2018-08-03', '2018-08-03]
['Musique', 'Gaétan Leclerc chante Félix et…', '2018-08-17', '2018-08-17]'['Musique', 'The Ring of Fire : a Johnny Cash Experience', '2018-07-21', '2018-07-21]
['Musique', "Jazz'Art", '2018-07-27', '2018-07-29]
['Musique', 'Génération Crooners', '2018-07-07', '2018-07-07]'['Musique', 'Fiesta Latina avec Me llamo Son', '2018-07-14', '2018-07-14]
['Musique', "L'avenue Royale fête l'été!", '2018-08-25', '2018-08-25]
['Musique', 'Concert au jardin', '2018-07-04', '2018-07-04]'['Musique', 'Concert au jardin', '2018-07-11', '2018-07-11]]
So im having trouble doing a list of those lists and removing the '\n' in my lists.
What I have tried:
I tried so many things that i cant even remember. This is the only code that allowed me to remove the backslash while being able to seperate my list with a " " using the split function. I had a hard time using .split() and a bunch of other stuff on a list.