Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,844 questions

55,671 answers

573 users

How to print the stack frames of the current execution thread of the program in Python

1 Answer

0 votes
import inspect

for frame in inspect.stack():
    print(frame)


  
'''
run:
  
FrameInfo(frame=<frame at 0x7a9216953cc0, file '<main.py>', line 4, code <module>>, filename='<main.py>', lineno=3, function='<module>', code_context=None, index=None, positions=Positions(lineno=3, end_lineno=3, col_offset=13, end_col_offset=28))
FrameInfo(frame=<frame at 0x7a9216953ed0, file '<string>', line 73, code <module>>, filename='<string>', lineno=73, function='<module>', code_context=None, index=None, positions=Positions(lineno=73, end_lineno=73, col_offset=4, end_col_offset=38))

'''

 



answered Jul 19, 2025 by avibootz

Related questions

3 answers 173 views
1 answer 280 views
1 answer 336 views
1 answer 353 views
...