▲ 96 ▼ which python trick or hack you know that you would want to share? (lemmy.ca) submitted 2 years ago by kionite231@lemmy.ca to c/programming@programming.dev 43 comments fedilink hide all child comments
[–] SpeakinTelnet@sh.itjust.works 57 points 2 years ago (5 children) My secret to high uptime: while True: try: main() except: pass permalink fedilink source hideshow 10 child comments replies: [–] kionite231@lemmy.ca [S] 9 points 2 years ago that was hilarious xD permalink fedilink source parent [+] Phegan@lemmy.world 4 points 2 years ago* (last edited 7 months ago) [deleted] permalink fedilink source parent [–] alexdeathway@programming.dev 4 points 2 years ago Flask developer? permalink fedilink source parent [–] CallMeButtLove@lemmy.world 3 points 2 years ago (3 children) Lurking beginner here, why is this bad? permalink fedilink source parent hideshow 6 child comments replies: [–] LKC@sh.itjust.works 23 points 2 years ago Basically sweeps errors under rug. No error handling and go again. permalink fedilink source parent [–] SpeakinTelnet@sh.itjust.works 12 points 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] CallMeButtLove@lemmy.world 2 points 2 years ago Thank you for that answer! That makes sense. permalink fedilink source parent [–] ResoluteCatnap@lemmy.ml 4 points 2 years 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. permalink fedilink source parent [+] LKC@sh.itjust.works 1 point 2 years ago [deleted] permalink fedilink source parent
[–] kionite231@lemmy.ca [S] 9 points 2 years ago that was hilarious xD permalink fedilink source parent
[+] Phegan@lemmy.world 4 points 2 years ago* (last edited 7 months ago) [deleted] permalink fedilink source parent
[–] alexdeathway@programming.dev 4 points 2 years ago Flask developer? permalink fedilink source parent
[–] CallMeButtLove@lemmy.world 3 points 2 years ago (3 children) Lurking beginner here, why is this bad? permalink fedilink source parent hideshow 6 child comments replies: [–] LKC@sh.itjust.works 23 points 2 years ago Basically sweeps errors under rug. No error handling and go again. permalink fedilink source parent [–] SpeakinTelnet@sh.itjust.works 12 points 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] CallMeButtLove@lemmy.world 2 points 2 years ago Thank you for that answer! That makes sense. permalink fedilink source parent [–] ResoluteCatnap@lemmy.ml 4 points 2 years 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. permalink fedilink source parent
[–] LKC@sh.itjust.works 23 points 2 years ago Basically sweeps errors under rug. No error handling and go again. permalink fedilink source parent
[–] SpeakinTelnet@sh.itjust.works 12 points 2 years ago (1 child) 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 permalink fedilink source parent hideshow 2 child comments replies: [–] CallMeButtLove@lemmy.world 2 points 2 years ago Thank you for that answer! That makes sense. permalink fedilink source parent
[–] CallMeButtLove@lemmy.world 2 points 2 years ago Thank you for that answer! That makes sense. permalink fedilink source parent
[–] ResoluteCatnap@lemmy.ml 4 points 2 years 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. permalink fedilink source parent