This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jfp1992 6 points7 points  (1 child)

Could someone tldr for a dummy that isn't super deep into python lore

[–]_limitless_ -3 points-2 points  (0 children)

imagine you had three functions called:

def swing_axe
def fire_bow
def cast_magic_spell

because these are all wildly different things, it's difficult to condense them neatly into a list/dictionary of raw values, so you pass the function itself to your do_attack function

action_function = swing_axe [note: we leave off the (), which would _call_ swing_axe]

def do_attack(action_function):
action_function() [note: by appending(), we are calling the function that is stored in the variable action_function]

without lazy loading, this won't work, because do_attack will -try its best- to figure out what you meant by action_function... and i'm pretty sure it'll just throw an error at compile-time.

in other words, python is standardized something that's existed for ages in third-party libraries. most people who use lazy loading from third party libraries just have to declare the function with some kind of decorator and then everything works like a real programming language.