Also, do y’all call main() in the if block or do you just put the code you want to run in the if block?

  • Sinthesis@lemmy.today
    link
    fedilink
    English
    arrow-up
    17
    ·
    edit-2
    2 days ago

    I use if__name__main__ often when working with AWS Lambda, but I also want to run it locally. Lambda wants to call a function with the params event and context. So I would do something like this:

    def handler(event, context):
        things
        return {
            'statusCode': 200,
            'body': 'Hello from Lambda!'
        }
    
    if __name__ == '__main__':
        event = {}
        context = {}
        response = handler(event, context)
        print(response)