Thursday, 19 September 2013

Can't select a value from list

Can't select a value from list

I have this code:
import os
import pprint
print("Hello")
ModList = os.listdir("C:/Users/Dat/AppData/Roaming/.minecraft/mods")
print ("The current mods you have installed are:\n")
pprint.pprint(ModList)
DisableNumber = input("To disable a mod, type it's number in the list.\n")
int (DisableNumber)
FileToDisable = ModList[DisableNumber]
print (FileToDisable)
It's supposed to list the files in a directory, print the list, ask the
user to input a number, and it renames the filename with that index in the
list. However, when I run this, I get an error:
Traceback (most recent call last):
File "C:\Users\Dat\Desktop\Python\ModDisabler.py", line 9, in <module>
FileToDisable = ModList[DisableNumber]
TypeError: list indices must be integers, not str
What is the cause of this error? I think it's because the
int(DisableNumber) is not working, but I can't seem to find out why for
the life of me. Am I missing something?

No comments:

Post a Comment