I have 2 modules as:
main.pyget.py
In main.py, I need to call a function present in get.py which is call_get(). So I'm trying it this way:
import get get.call_get() But it throws an error as 'Attribute Error'. On the other hand, the following code works:
import temp temp.func() function func in temp.py looks as:
import get get.call_get() I am unable to understand this behaviour. Please guide.
get.py code:
import requests import json import sys import utils import error_handler import get_helper import os import pvdata def call_get(): try: auth_tuple = utils.get_auth_details("get") headers = utils.get_header() resource_types = utils.get_resource_types() namespaces = utils.get_namespaces() if resource_types[0].lower() == "all": resource_types = utils.append_all_resources() get_helper.get_namespace_list(auth_tuple, headers) all_namespaces = utils.extract_namespaces_from_list("source") if namespaces[0].lower() != "all": error_handler.validate_source_namespaces(namespaces, all_namespaces) utils.create_file( "Namespaces", "All_namespaces_at_source.txt", str(all_namespaces)) get_helper.generate_json_for_all_namespaces( all_namespaces, auth_tuple, headers) for resource_name in resource_types: if namespaces[0].lower() == "all": for namespace in all_namespaces: get_helper.call_all_functions_for_get( namespace, resource_name, headers, auth_tuple) else: for namespace in namespaces: get_helper.call_all_functions_for_get( namespace, resource_name, headers, auth_tuple) except Exception as error: filename = os.path.basename(__file__) error_handler.print_exception_message(error, filename) return if __name__ == "__main__": call_get() main.py code:
import utils import remote_exec import post import get import error_handler import os import handle_space import socket import json from requests import get import sys import temp def only_dest_requires_jumpserver(): try: dictionary = { "migration_type": utils.config_data()["source_cloud"] + " to " + utils.config_data()["dest_cloud"] } utils.update_config_file(dictionary) print("\nInitialising " + utils.config_data()["source_cloud"] + " to " + utils.config_data()["dest_cloud"] + " migration...") hostname = socket.gethostname() if hostname == utils.config_data()["my_hostname"]: # get.call_get() temp.func() print("\nData successfully exported from source to this machine.\nChecking for space availability at jumpserver...") print("Done!") except Exception as error: filename = os.path.basename(__file__) error_handler.print_exception_message(error, filename)
get.py. You either have a spelling error, or the function is part of a class or something.get.pycode. No cicular imports.main.py?import getfrom requests import get