In this program I have a lot of game directories in a list like so:

base = "C:/Program Files/Game"
expansion  = "C:/Program Files/Game/Expansion"

Games = [(base, "Base Game"),(expansion, "Expansion 1")]
Installed = []

The program then sees if they are installed like this:

for path, name in Games:      #For every path and name in Games list,
        if os.path.isdir(path):     #If the path exists,
            Installed.append(name)  #Add its NAME to the Installed list.      
    print "\n----------- Games Installed ------------"
    for name in Installed: print name

Now it must check to see if a file is in the games that are in the Installed list. If it is not there, the name of the game must be printed and the file copied to the game's directory.

for path in Installed:
        if not os.path.isfile(path + "d3dx9_31.dll"):
            Ok = False
            print "DLL not found in %s. Installing..." % name
            shutil.copy2(programRoot + "d3dx9_31.dll", path + "d3dx9_31.dll")
            
            if os.path.isfile(path + "d3dx9_31.dll"): print "DLL sucessfully installed.\n"    
            else: raise NotFoundError("Couldn't find DLL after copying to %s" % name)
            #Custom error class

In order for that to work correctly, the path AND name of the game must be added to the Installed list just like it is in the Games list.


Well that's simple. Just change the second block of code to this:

for path, name in Games:      #For every path and name in Games list,
        if os.path.isdir(path):     #If the path exists,
            Installed.append(path, name)  #Add its path and name to the Installed list.      
    print "\n----------- Games Installed ------------"
    for name in Installed: print name

Nope, nevermind. That does not work as append takes only one argument! Now I don't know what to do. :(

Recommended Answers

All 2 Replies

You took out tuple and put it in two variables path and name.

Now you only reconstruct it for the single parameter:

Installed.append((path,name))

Yes..That seems to have worked. Thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.