Skip to content
Advertisement

Calling an inner function in Python

I have this final main.py that combines every function I wrote separately, but I can’t make it work, it actually returns the Success at the end but it actually does nothing nor in my local folders or MongoDB. The function is this one:

JavaScript

My goal is that, when I call gw2_etl(), it runs every process inside (log_scrape, store_data and mongo_connect) and returns the Success message at the end. I’m probably doing it wrong since it neither runs anything nor send an error message.

For the mongo connection, I need to return the stats_dict, since it is the JSON file that I want to upload there, csv file is just for local storage.

I actually got some bosses out since the code it’s actually pretty long.

If you have any hint or clue about how could I make this work, I would be incredibly grateful.

Advertisement

Answer

You still need to call all of those functions separately from within the gw2_etl() before returning from the function. Defining functions inside another just means you can’t access them outside of the outer function. So before the return statement add

JavaScript

and continue from there. You’ll notice that you need to carry over some variables to invoke the functions with the correct arguments, but I left that part for you to figure out.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement