We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,420 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Format Question

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
13 Hours
Discussion Span
3 Months Ago
Last Updated
4
Views
Question
Answered
clouds_n_things
Light Poster
48 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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)]
pyTony
pyMod
Moderator
6,312 posts since Apr 2010
Reputation Points: 879
Solved Threads: 987
Skill Endorsements: 26

Got it, that worked...sorry if that sounded unclear. :)

clouds_n_things
Light Poster
48 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 3 Months Ago by pyTony

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0618 seconds using 2.68MB