-1

Is it possible to use try without except? Sometimes it doesn't matter if some iterations crash, but using conditions (maybe more than one) looks weirdly

# in my dreams:

for i in lines:
    try:
        print(i[3])
  • If you just want to do nothing in the error case, see https://docs.python.org/3/library/contextlib.html#contextlib.suppress – jonrsharpe Dec 04 '20 at 20:24

1 Answers1

0

Try needs an except or finally block following it. If you want to leave it empty, try this

try:
    /*Your code here*/
except:
    pass

EDIT: If you're confident that your block won't raise an exception, you could just remove the try block altogether

for i in lines:
    print(i[3])
treycrossley
  • 143
  • 1
  • 8