P
P
Python Newbie2021-11-19 08:59:22
Python
Python Newbie, 2021-11-19 08:59:22

How to jump to a specific line of code in python?

Hello, is it possible to do this in python: when I catch an exception, I do some action (for example driver.refresh()) and run the code again from the line in which the exception occurred

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2021-11-19
@Levman5

The meaning is this:

while True:   # вечный цикл
    try:
        # действия
        break # выход из цикла, если действия прошли успешно
    except Exception:
        pass # В случае ошибки ничего не делать.
        # Или вместо pass написать continue, чтобы было очевидно,
        # что надо сразу перейти к следующей итерации.

In general, it would be necessary to take into account the number of attempts and catch a specific, not a general, exception.

R
Ronald McDonald, 2021-11-19
@Zoominger

You can do it, but are you sure that try / except is needed here? Maybe check the conditions for the correctness of the work?
If you could post the code, it would be possible to tell.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question