Reputation: 279
So I imagine this is a fairly simple question where I just don't understand the error. This is my current code:
# SINGLE CHOICE INPUT
choices = ["Auto", "Manual", "Manual (code only)"]
chooseOneBox = wx.SingleChoiceDialog(None, "Setup / Opsætning", "Setup / Opsætning", choices)
if chooseOneBox.ShowModal() == wx.ID_OK:
setupChoice = choices.index[chooseOneBox.GetStringSelection()] + 1
if setupChoice == 1:
print(choices[setupChoice]-1)
elif setupChoice == 2:
print(choices[setupChoice]-1)
print(choices[setupChoice])
So I have the list choices
which contains a bunch of options which are being correctly displayed in chooseOneBox
. When trying to do:
setupChoice = choices.index[chooseOneBox.GetStringSelection()] + 1
I get the following error: 'builtin_function_or_method' object is not subscriptable
.
I want to convert the string from chooseOneBox
to an integer for simplistic reasons. How do I avoid getting that error?
Upvotes: 1
Views: 51
Reputation: 22443
I dont see any advantage to the way that you're performing that code.
Why not this instead:
choices = ["Auto", "Manual", "Manual (code only)"]
chooseOneBox = wx.SingleChoiceDialog(None, "Setup / Opsætning", "Setup / Opsætning", choices)
if chooseOneBox.ShowModal() == wx.ID_OK:
setupChoice = choices.index(chooseOneBox.GetStringSelection())
print(choices[setupChoice])
Or even more straightforwardly, using GetSelection()
which returns the index of the item selected:
choices = ["Auto", "Manual", "Manual (code only)"]
chooseOneBox = wx.SingleChoiceDialog(None, "Setup / Opsætning", "Setup / Opsætning", choices)
if chooseOneBox.ShowModal() == wx.ID_OK:
print(choices[chooseOneBox.GetSelection()])
Upvotes: 1
Reputation: 1875
index
is a function of the list
that returns the first index of occurrence of an item.
Replace
choices.index[chooseOneBox.GetStringSelection()] + 1
With this
choices.index(chooseOneBox.GetStringSelection()) + 1
Upvotes: 1