0

Really quick question, if I want to return the data that is returned by snesVar in videoGame as a string on every line, what is the correct code to use?

def videoGame():
    count = 0 
    snesVar = []
    for data in os.listdir('/SNES/SNES Roms'):
        if data.endswith('.src') or data.endswith('.srm'):
            snesVar.append(data)  
    return snesVar

def videoGame2():
    gbaVar = []
    count = 0 
    for data in os.listdir('GBA'):
        if data.endswith('.gba') or data.endswith('.gb'):
            gbaVar.append(data)
    return gbaVar

def videoGame3():
    ndsVar = []
    count = 0 
    for data in os.listdir('NDS'):
        if data.endswith('.nds') or data.endswith('.ds'):
            ndsVar.append(data) 
    return ndsVar
2
Contributors
2
Replies
6
Views
4 Years
Discussion Span
Last Post by clouds_n_things
1

Your functions are duplicates, you only need one to return the file names. I do not understand your question.

def video_game(game_dir='/SNES/SNES Roms', extensions=('.src','srm')):
    return [file_name for file_name in os.listdir(game_dir) if data.endswith(extensions)]
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.