generated from Pseudo-Lab/Jupyter-Book-Template
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# 6주차 | ||
|
||
## 파이썬에서 프레임 객체 접근해보기 | ||
```python | ||
import inspect | ||
|
||
|
||
def print_frame_info(): | ||
frame = inspect.currentframe().f_back | ||
try: | ||
print("Function Name:", frame.f_code.co_name) | ||
print("File Name:", frame.f_code.co_filename) | ||
print("Line No:", frame.f_back.f_lineno) | ||
print("Local Variables:", list(frame.f_locals.keys())) | ||
print("Global Variables:", list(frame.f_globals.keys())) | ||
finally: | ||
del frame | ||
|
||
|
||
def print_sum(n1, n2): | ||
sum = n1 + n2 | ||
print(sum) | ||
print_frame_info() | ||
|
||
|
||
def print_upper(word): | ||
upper_word = word.upper() | ||
print(upper_word) | ||
print_frame_info() | ||
|
||
|
||
print_sum(10, 20) | ||
print_upper("Python") | ||
``` | ||
<img width="1241" alt="스크린샷 2024-05-12 오후 8 14 24" src="https://github.com/mikaniz/CPython-Guide/assets/92143119/3112a037-a34f-4ab0-8a56-ae7a413af38a"> |