In Python how to pass objects from one module to another?

There are 3 modules: main, authorisate, resolve_domain.
From the main start up all the modules. In authorisate authorization Vkontakte with vk_api, vk returns objects and tools that should be used in other modules. In resolve_domain group name converted to id. While everything was in one file - worked.
Question: how to pass session authorization (vk) of authorisate in other modules in which the functions and classes?
Now gives an error:
File "C:\Source\vk\resolvedomain.py", line 6, in resolve_domain
 resolve_domain = vk.resolveScreenName(screen_name=domain)
AttributeError: 'tuple' object has no attribute 'resolveScreenName'

the main module
def main():
logger.log()
 vk = authorisation.authorisate()
 print(resolvedomain.resolve_domain('group_domain', vk))

if __name__ == '__main__':
 sys.exit(main())


module authorisate
def authorisate():
 conf = configparser.RawConfigParser()
conf.read('config.cfg')
 login = conf.get('account', 'login')
 password = conf.get('account', 'password')
 vk_session = vk_api.VkApi(login, password, captcha_handler=captcha_handler)
 vk_session.auth() 
 vk = vk_session.get_api()
 tools = vk_api.VkTools(vk_session)
 return vk, tools


module resolve_domain
def resolve_domain(domain):
 resolve_domain = vk.resolveScreenName(screen_name=domain)
 id_from_domain = 0 - resolve_domain['object_id']
 print('resolve ', id_from_domain)
 return id_from_domain


P. S. all that is needed is in the module main comma-separated list: vk, tools = authorisation.authorisate() as the function returns 2 values and in the module resolve_domain to add the argument: def resolve_domain(domain, vk):
June 10th 19 at 14:31
2 answers
June 10th 19 at 14:33
Solution
> AttributeError: 'tuple' object has no attribute 'resolveScreenName'
Well, the function call you returns two values - vk and tools
And you like a property of the object trying to reach
Thank you, helped, was removed from return the second return value and it worked, but the problem is that other modules need both the object of authorization and vk and tools. Don't understand how to implement it. - Lenora.Littel commented on June 10th 19 at 14:36
You don't the second value should be removed, and the right to take two arguments.
Something like
def main():
logger.log()
 vk, tools = authorisation.authorisate()
 print(resolvedomain.resolve_domain('group_domain', vk))
- Nathan_Gaylord commented on June 10th 19 at 14:39
June 10th 19 at 14:35
at random, decided to do so (may be crooked):
authorisate because the function returns a tuple of objects
when you call the function passed here a parameter *vk
id_from_domain = resolvedomain.resolve_domain('lunev_network', *vk)

in the function itself instead of hard-coded argument to get a tuple of *args and then from it extract the desired object:
def resolve_domain(domain, *args):
 vk = args[0]
 resolve_domain = vk.resolveScreenName(screen_name=domain)
why are you suggested as well, and if you resolve_domain use only vk, so give him, specifically, but not all args you on and not using - Lenora.Littel commented on June 10th 19 at 14:38
thanks
the latest implementation looks like this:
from the tuple received from return allocate 2 elements, we need to send a argument to the function:
def main():
logger.log()
 vk_and_tools = authorisation.authorisate()
 vk = vk_and_tools[0]
 tools = vk_and_tools[1]
 id_from_domain = resolvedomain.resolve_domain('lunev_network', vk)

def resolve_domain(domain, vk):
 resolve_domain = vk.resolveScreenName(screen_name=domain)
 id_from_domain = 0 - resolve_domain['object_id']
 print('resolve ', id_from_domain)
 return id_from_domain
- Nathan_Gaylord commented on June 10th 19 at 14:41
you read that writing ? don't need no vk_and_tools, all in one line is - Garnett_Deckow commented on June 10th 19 at 14:44
Hard-nosed )). To your question came up with the crutch, but still said its the only right thing to do. - Lenora.Littel commented on June 10th 19 at 14:47
sorry, I didn't notice that in your answer to the left there is a listing of vk, tools = authorisation.authorisate(), thanks don't need my "garden" with a selection from a tuple
didn't even know that was possible, everything was corrected and changed to "mark solution" is your answer - Garnett_Deckow commented on June 10th 19 at 14:50

Find more questions by tags Python