I've read a thread on what a (non)subscriptable object is but it doesn't tell me what i can do about it.
I have a code calling a mypost
private module. The aim is to set up mail accounts and to do this i create MailAccounts()
objects defined in the mypost
module. Quantity of accounts and their respective details are described in a configuration file. When the application starts, it collects account information and stores it in a dictionary, the structure of which is: accounts = {service : { <MailAccounts Object at xxxxx> : {username : myusername, password : mypassword}}}
where service
can be "gmail" and where MailAccounts
is the class defined in the mypost
module.
So far so good. When however i want to setup the account, i need to call its method: MailAccounts.setupAccount(username, password)
. I do this by iterating each MailAccount object of the dictionary and ask to run the method:
for service in accounts:
for account in accounts[service]:
account.setupAccount(account['username'], account['password'])
But as you may have guessed it didn't work, Python returns:
TypeError: 'MailAccount' object is not subscriptable
If i create the same account manually however it works:
account = MailAccount()
account.setupAccount('myusername', 'mypassword')
Now i believe it has something to do with the fact that my <MailAccount Object at xxxx>
is a dictionary key right? That makes it non-subscriptable (whatever that may mean)?
No what exactly does this mean to be non-subscriptable? What does it imply in this example? And of course: how can i solve / bypass this in this case?
Thanks, Benjamin :)