2018年1月10日 星期三

Python: Print the current call stack

Python: Print the current call stack

Python Basic: Exercise-96 with Solution

Write a Python program to print the current call stack.
Sample Solution:-
import sys
import traceback

def func1():
    raise NameError("--func1 exception--")

def func2():
    func1()

def main():
    try:
        func2()
    except Exception as e:
        traceback.print_exc(limit=1, file=sys.stdout)


if __name__ == '__main__':
    main()

========== RESTART: F:\Python_APSC\py-ex-basic-96.py ==========
Traceback (most recent call last):
  File "F:\Python_APSC\py-ex-basic-96.py", line 13, in main
    func2()
NameError: --func1 exception--
>>> 

沒有留言:

張貼留言

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構

MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 這張圖片展示了一個 結合 MQTT 協定與 Modbus 通訊的遠端監控與控制系統架構 (主要透過 Node-RED 進行資料整合)。 系統包含三個核心部分,其運作功能說明如下: 1. ESP32 終端設備(硬體控制層...