Fix Python – Better to ‘try’ something and catch the exception or test if it’s possible first to avoid an exception?

Should I test if something is valid or just try to do it and catch the exception?

Is there any solid documentation saying that one way is preferred?
Is one way more pythonic?

For example, should I:
if len(my_list) >= 4:
x = my_list[3]
else:
x = ‘NO_ABC’

Or:
try:
x = my_list[3]
except IndexError:
x = ‘NO_ABC’

Some thoughts…
P….

Fix Python – Why is “except: pass” a bad programming practice?

I often see comments on other Stack Overflow questions about how the use of except: pass is discouraged. Why is this bad? Sometimes I just don’t care what the errors are and I want to just continue with the code.
try:
something
except:
pass

Why is using an except: pass block bad? What makes it bad? Is it the fact that I pass on an error o….

Fix Python – Is it a good practice to use try-except-else in Python?

From time to time in Python, I see the block:
try:
try_this(whatever)
except SomeException as exception:
#Handle exception
else:
return something

What is the reason for the try-except-else to exist?
I do not like that kind of programming, as it is using exceptions to perform flow control. However, if it is included in the language, there….

Fix Python – How to catch and print the full exception traceback without halting/exiting the program?

I want to catch and log exceptions without exiting, e.g.,
try:
do_stuff()
except Exception as err:
print(Exception, err)
# I want to print the entire traceback here,
# not just the exception name and details

I want to print the exact same output that is printed when the exception is raised without the try/except intercepting the e….