Oct-24-2024, 04:08 PM
(This post was last modified: Oct-24-2024, 04:08 PM by BoredBannana.)
Hey guys,
I'd like to preface, that I'm a complete beginner - this is actually my first bit of code outside of isolated lesson structures.
So I inted to build some sort of offline spotify clone for my music.
My file structure in the O:\DB folder looks like this
DB
Grimes / Art Angels / Song1, Song 2 ...
Interpol / Our Love to Admire / Song 1, Song 2...
Tool / Lateralus / Song1, Song 2...
Now the code is supposed to fetch data from the structure, so that I can neatly export the results into an sqlite library, with minimal manual labor. From there I'll create the connections via 1-n IDs.
wheras the comment print inside the loop does give me my desired outcome of
artists = [ [Name: Grimes, O:/DB/Grimes], [Name: Interpol, O:/DB/Interpol], [Name: Tool, O:/DB/Tool] ] .
Why is that ? And how do I get my funtion to produce my desired outcome? It works with temp.extend(), but that gives me only one list with all the data.
Also, if I remove the temp.clear() line, why do I get 3 x [ [Name: Grimes, O:/DB/Grimes, Name: Interpol, O:/DB/Interpol, Name: Tool, O:/DB/Tool ]
instead of
[Name: Grimes, O:/DB/Grimes]
[Name: Grimes, O:/DB/Grimes, Name: Interpol, O:/DB/Interpol]
[Name: Grimes, O:/DB/Grimes, Name: Interpol, O:/DB/Interpol, Name: Tool, O:/DB/Tool]
thanks in advance
I'd like to preface, that I'm a complete beginner - this is actually my first bit of code outside of isolated lesson structures.
So I inted to build some sort of offline spotify clone for my music.
My file structure in the O:\DB folder looks like this
DB
Grimes / Art Angels / Song1, Song 2 ...
Interpol / Our Love to Admire / Song 1, Song 2...
Tool / Lateralus / Song1, Song 2...
Now the code is supposed to fetch data from the structure, so that I can neatly export the results into an sqlite library, with minimal manual labor. From there I'll create the connections via 1-n IDs.
artists = [] temp = [] def fetch(source): global artists, temp for entry in os.listdir(source): name = f"Name: {entry}" temp.append(name) folder_path = os.path.join(source, entry) temp.append(folder_path) artists.append(temp) # print(artists) temp.clear() fetch(O:/DB) print(artists)The last line print(artists) hands out only empty lists like artists = [[], [], []]
wheras the comment print inside the loop does give me my desired outcome of
artists = [ [Name: Grimes, O:/DB/Grimes], [Name: Interpol, O:/DB/Interpol], [Name: Tool, O:/DB/Tool] ] .
Why is that ? And how do I get my funtion to produce my desired outcome? It works with temp.extend(), but that gives me only one list with all the data.
Also, if I remove the temp.clear() line, why do I get 3 x [ [Name: Grimes, O:/DB/Grimes, Name: Interpol, O:/DB/Interpol, Name: Tool, O:/DB/Tool ]
instead of
[Name: Grimes, O:/DB/Grimes]
[Name: Grimes, O:/DB/Grimes, Name: Interpol, O:/DB/Interpol]
[Name: Grimes, O:/DB/Grimes, Name: Interpol, O:/DB/Interpol, Name: Tool, O:/DB/Tool]
thanks in advance