Dendarii
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
whoareu@lemmy.ca to Programming@programming.devEnglish · 11 months ago

which python trick or hack you know that you would want to share?

message-square
message-square
45
fedilink
96
message-square

which python trick or hack you know that you would want to share?

whoareu@lemmy.ca to Programming@programming.devEnglish · 11 months ago
message-square
45
fedilink
  • SpeakinTelnet@sh.itjust.works
    link
    fedilink
    arrow-up
    61
    arrow-down
    3
    ·
    11 months ago

    My secret to high uptime:

    while True:
        try:
            main()
        except:
            pass
    
    • whoareu@lemmy.caOP
      link
      fedilink
      arrow-up
      11
      arrow-down
      2
      ·
      11 months ago

      that was hilarious xD

    • Phegan@lemmy.world
      link
      fedilink
      arrow-up
      4
      ·
      11 months ago

      Someone is absolutely going to think this is a real recommendation and do it.

    • alexdeathway@programming.dev
      link
      fedilink
      arrow-up
      4
      ·
      11 months ago

      Flask developer?

    • CallMeButtLove@lemmy.world
      link
      fedilink
      arrow-up
      3
      ·
      11 months ago

      Lurking beginner here, why is this bad?

      • LKC@sh.itjust.works
        link
        fedilink
        arrow-up
        24
        ·
        11 months ago

        Basically sweeps errors under rug.

        No error handling and go again.

      • SpeakinTelnet@sh.itjust.works
        link
        fedilink
        arrow-up
        13
        ·
        11 months ago

        There you go:

        # Start an infinite loop because True will always be True
        while True: 
            # try to run the main function, usually where everything happens
            try:
                main()
            # in the case an exception is raised in the main function simply discard (pass) and restart the loop
            except:
                pass
        
        • CallMeButtLove@lemmy.world
          link
          fedilink
          arrow-up
          2
          ·
          11 months ago

          Thank you for that answer! That makes sense.

      • ResoluteCatnap@lemmy.ml
        link
        fedilink
        English
        arrow-up
        4
        ·
        11 months ago

        This gives some better context. https://stackoverflow.com/questions/21553327/why-is-except-pass-a-bad-programming-practice

        But essentially ignoring every single error a program could generate is not great. It’d be better to know what those errors are and fix/prevent them from occurring in the first place.

    • LKC@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      11 months ago

      deleted by creator

Programming@programming.dev

programming@programming.dev

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 294 users / day
  • 732 users / week
  • 2.86K users / month
  • 7K users / 6 months
  • 1 local subscriber
  • 20.1K subscribers
  • 1.47K Posts
  • 19.9K Comments
  • Modlog
  • mods:
  • snowe@programming.dev
  • Ategon@programming.dev
  • MaungaHikoi@lemmy.nz
  • BE: 0.19.9
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org