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 WS HMI 與 Wokwi ESP32 連線的資訊透過HiveMQ

MQTT WS HMI 與 Wokwi ESP32 連線的資訊透過HiveMQ     https://console.hivemq.cloud/clusters 當您進入 HiveMQ Cloud Console 的 Clusters 頁面時,您的目標是取得能讓 MQTT W...