I am learning Python. I have come to the point were my functions, that have loops can't call other functions from within the loop because otherwise I get duplicate results, so I want to create a function that calls each function, gets the data out of them and assigns them to functions that execute after and need that data to work, avoiding looping.
So let's say I have this function :
def get_sound():
for dirpath, directories, files in os.walk(XPATH):
for sound_file in files:
date = artist = album = title = ""
if sound_file.endswith('.flac'):
print('Flac file found, getting metadata and renaming...')
flac_file = os.path.join(dirpath, sound_file)
from mutagen.flac import FLAC
metadata = mutagen.flac.Open(flac_file)
for (key, value) in metadata.items():
if key.startswith("date"):
date = value[0]
if key.startswith("artist"):
artist = value[0]
if key.startswith("album"):
album = value[0]
if key.startswith("title"):
title = value[0]
final_name = (date + " - " + artist +
" - " + album + " - " + title)
dest_file = os.path.join(dirpath, final_name)
os.renames(flac_file, dest_file)
return (dest_file, final_name, artist, album, title)
From that function, I got a tuple of data. Now, what I want to do is to create a function :
def main():
get_sound()
find_key()
make_video()
get_sound()
will return data, find_key()
will also return data, and make_video()
will use both data to fill certain variables and execute a command with them. As the data returned has no identifier, how do I pass get_sound()
and find_key()
returned data to make_video
?