Get the App
SLTechnology News&Howtos  ›  Development  › 

How python uses goto to jump to a specified line of code

Shulou Source: shulou.com Published: 2022-06-01 13:33:56 09月17日 Update

Most people do not understand the knowledge points of this article "python how to use goto to jump to the specified line of code", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "python how to use goto to jump to the specified line of code" article.

1. The reason is to encounter such a problem in the actual development:

The following is the pseudo code

If embedding.model is not exist: calculate embedding # # moudel_1 save embedding.modelelse: embedding = load embedding.modeltry: use embeddingexcept KeyError: calculate embedding # # this is the same as moudel_1.

Find that you need to paste the previously written calculate embedding in except.

The simple summary is as follows:

Somecode_1try: somecode_2except: somecode_3 somecode_1 # # re-execute 2. Use goto (1) to install gotopip install goto-statement (2) use goto to complete a small example

Define function

From goto import with_goto@with_goto # must have def test (list_): tmp_list = list_ label.begin # identifies where to jump and start execution result = [] try: for I J in enumerate (list_): tmp = 1 / j result.append (tmp) last_right_i = i except ZeroDivisionError: del tmp_ list [last _ right_i + 1] goto.begin # start return result where there is a jump mark

Running

A = test ([1,3,4,0,6]) print (a)

Result

[1.0, 0.3333333333333333, 0.25, 0.16666666666666666]

Note: if you run label and goto on ide Mountain, there is a red wavy line error. You don't have to worry about it and just execute it.

Add: Pycharm jumps back to the previous line of code

I've been writing Python code in Pycharm for some time, and there's a problem that has been bothering me: I often need to jump from one function to another when browsing the code, and sometimes the two functions are so far away that I don't know how to get back to the last function directly.

So my approach is to press ctr+F and then enter the function name of the previous function to locate and return to the previous function.

The above is about the content of this article on "how python uses goto to jump to a specified line of code". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

Tags: Functions code content place that is articles logos knowledge articles questions run consistent have do not use two value examples methods most actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Apple Docker Huawei