Python: how to deal with non-encrypted objects?

I read a thread about what a (non) subsector object is , but it does not tell me what I can do about it.

I have code calling a mypostprivate module. The goal is to create mail accounts, and for this I create objects MailAccounts()defined in the module mypost. The number of accounts and their corresponding data are described in the configuration file. When the application starts, it collects information about the account and saves it in a dictionary, the structure of which is: accounts = {service : { <MailAccounts Object at xxxxx> : {username : myusername, password : mypassword}}}where servicecan be "gmail", and MailAccountsis the class defined in the module mypost. So far, so good. However, when I want to set up an account, I need to call its method: MailAccounts.setupAccount(username, password). I do this by iterating through each object of the MailAccount dictionary and asking to run the method:

for service in accounts:
        for account in accounts[service]:
            account.setupAccount(account['username'], account['password'])

But, as you might have guessed that this did not work, Python returns:

TypeError: 'MailAccount' object is not subscriptable

If I create the same account manually, but it works:

account = MailAccount()
account.setupAccount('myusername', 'mypassword')

, , <MailAccount Object at xxxx> ? ( )?

, , ? ? , : / ?

, :)

+3
2

.

for service in accounts:
        for account, creds in accounts[service].iteritems():
            account.setupAccount(creds['username'], creds['password'])
+4

, , , .

>>> x = { 'a': 1, 'b': 2 }
>>> for item in x:
...     print(item)
... 
a
b

, :

>>> for item in x.values():
...     print(item)
... 
1
2

items :

>>> for item in x.items():
...     print(item)
... 
('a', 1)
('b', 2)
0

All Articles