A
A
azatbairamov2015-11-17 22:49:35
Python
azatbairamov, 2015-11-17 22:49:35

How to continue the execution of a Python 3 program after some of the commands gave an error?

Is it possible to make python work after NOT executing a certain command? i.e. if x==1: ... and the x variable is not specified, we print "Error" and continue the program execution. Many thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-11-17
@sim3x

https://docs.python.org/3/tutorial/errors.html

try:
    x = 1/0
except ZeroDivisionError:
    print("Try in another world")

Always indicate the error class! In this case, ZeroDivisionError
print should be used only at the initial level or at the prototyping stage - it is better to use the built-in logging

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question