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--
>>> 

沒有留言:

張貼留言

Fultter APP控制 WOKWI ESP32 RFID+LED (使用flutter_windows_3.19.1-stable Visual studio 1.108.2 )

Fultter APP控制 WOKWI ESP32 RFID+LED (使用flutter_windows_3.19.1-stable  Visual studio  1.108.2 ) 1) Android studio 環境設定 2) Visual studio  1.108...