How to call function within another function in Python?

Asked

Viewed 59 times

-3

Hey, you guys. I’m new to Python and need to deliver a script of requests Apis. There are three attributes required to request the API (client_id, client_secret and text), and the two "clients" are sensitive information and cannot be displayed in the script.

I created functions in the config file to take this two information, and in the main script I want to call. The point is that I am not able to call.

     def get_client_id():
         Config().get_client_id ##essa função chama o client_id que está no arquivo Config.py
    
     def get_client_secret():
         Config().get_client_secret ##essa função chama o client_id que está no arquivo Config.py
    
resp = NomeApi().request_api({self.get_client_id()}, {self.get_client_secret()}, texto="Q1JFQVRFIEVYVEVSTkFMIFR=")

#os get_clients não estão conseguindo chamar o valor que está na classe Config.py

Legend: Nomepi() is the class containing all functions request_api() is the main function to request the API

  • My guess is that the parentheses are missing at the end to call the methods (ex: Config().get_client_id()). But without seeing the whole code it’s hard to guess.

  • Thank you for the touch. I put the parentheses to keep the good practices, but it ran without also. I got a solution and put in the answer below. Valeuss!!

  • You don’t need to put "solved" in the title. I know it’s common in many forums, but here it works different. In your case, as you yourself have found the solution, it is enough mark your reply below as accepted, this is enough to indicate that it was solved (as it was yourself who answered, I think the system only allows you to do this after a few hours, but anyway, just wait for the deadline...)

1 answer

0


I got a solution.

I managed to call the function that was in another file (in my case Config.py) and run in this script. So the request returned right.

def get_client_id(cls):
        Config().get_client_id

    def get_client_secret(cls):
        Config().get_client_secret


resp = NomeApi().request_api(f"{Config().get_client_id()}", f"{Config().get_client_secret()}",
                               texto="Q1JFQVRHAJSOksuasnjJA=")

Browser other questions tagged

You are not signed in. Login or sign up in order to post.