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?

  • embed_me@programming.dev
    link
    fedilink
    arrow-up
    1
    ·
    6 months ago

    Sometimes I have the misfortune of working with python code written by someone else and I wonder how a language like this became anything more than a scripting language

    • addie@feddit.uk
      link
      fedilink
      arrow-up
      1
      ·
      6 months ago

      I feel that Python is a bit of a ‘Microsoft Word’ of languages. Your own scripts are obviously completely fine, using a sensible and pragmatic selection of the language features in a robust fashion, but everyone else’s are absurd collections of hacks that fall to pieces at the first modification.

      To an extent, ‘other people’s C++ / Bash scripts’ have the same problem. I’m usually okay with ‘other people’s Java’, which to me is one of the big selling points of the language - the slight wordiness and lack of ‘really stupid shit’ makes collaboration easier.

      Now, a Python script that’s more than about two pages long? That makes me question its utility. The ‘duck typing’ everywhere makes any code that you can’t ‘keep in your head’ very difficult to reason about.

  • Sinthesis@lemmy.today
    link
    fedilink
    English
    arrow-up
    0
    ·
    edit-2
    6 months 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)
    
  • MTK@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    edit-2
    6 months ago

    It really doesn’t. It’s a scripting language, functions are there but at it’s core it runs a script. The issue is that it was so easy to start with that people started doing everything in it, even though it sucks for anything past complex scripts

    It is the excel of databases.

      • MTK@lemmy.world
        link
        fedilink
        arrow-up
        0
        arrow-down
        1
        ·
        6 months ago

        I didn’t say it wasn’t real, it’s just a scripting structure and not object oriented, so it doesn’t make sense for it to start by looking for a “main” object