zoukankan      html  css  js  c++  java
  • goto for Python

    http://entrian.com/goto/
    看了看源代码,原来是通过给所有函数修改trace,然后在异常时就会执行设置的函数
    # Install the trace function, including all preceding frames.
    sys.settrace(_trace)
    frame = sys._getframe().f_back
    while frame:
    frame.f_trace = _trace
    frame = frame.f_back
    改天有时间看看如何在trace中分析每一行代码的!

    # Example 1: Breaking out from a deeply nested loop:
    from goto import goto, label
    for i in range(1, 10):
    for j in range(1, 20):
    for k in range(1, 30):
    print i, j, k
    if k == 3:
    goto .end
    label .end
    print "Finished\n"


    # Example 2: Restarting a loop:
    from goto import goto, label
    label .start
    for i in range(1, 4):
    print i
    if i == 2:
    try:
    output = message
    except NameError:
    print "Oops - forgot to define 'message'! Start again."
    message = "Hello world"
    goto .start
    print output, "\n"

  • 相关阅读:
    css
    js
    css3
    css
    深浅拷贝
    index-数据结构/算法
    es6知识点
    在vscode中配置sass savepath
    计算机基础
    element-ui使用后手记
  • 原文地址:https://www.cnblogs.com/cutepig/p/1312242.html
Copyright © 2011-2022 走看看