Skip to content

Commit 09bc781

Browse files
committed
misc: Add fn_names for debug purposes
1 parent 2631d30 commit 09bc781

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

ofunctions/misc/__init__.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515

1616
__intname__ = "ofunctions.misc"
1717
__author__ = "Orsiris de Jong"
18-
__copyright__ = "Copyright (C) 2014-2024 Orsiris de Jong"
18+
__copyright__ = "Copyright (C) 2014-2026 Orsiris de Jong"
1919
__description__ = "Collection of various functions"
2020
__licence__ = "BSD 3 Clause"
21-
__version__ = "1.8.0"
22-
__build__ = "2024042401"
21+
__version__ = "1.8.1"
22+
__build__ = "2026031001"
2323
__compat__ = "python2.7+"
2424

2525

@@ -37,8 +37,24 @@
3737

3838
# Get current function name, can take int argument to get higher caller names
3939
# eg fn_name(1) will return caller name, fn_name(2) will return caller of caller name
40+
# Balantly copied from https://stackoverflow.com/a/31615605/2635443
4041
fn_name = lambda n=0: sys._getframe(n + 1).f_code.co_name
4142

43+
fn_names = lambda: [
44+
sys._getframe(i).f_code.co_name for i in range(1, sys._getframe().f_back.f_lineno)
45+
]
46+
47+
def fn_names():
48+
"""
49+
Get all caller function names in a list, starting with the closest one
50+
"""
51+
frame = sys._getframe(1)
52+
names = []
53+
while frame:
54+
names.append(frame.f_code.co_name)
55+
frame = frame.f_back
56+
return names
57+
4258

4359
def rot13(string):
4460
# type: (str) -> str
@@ -566,10 +582,3 @@ def human_bits(self):
566582
def human_iec_bits(self):
567583
unit_list = [unit for unit in self.bits_units if "i" in unit]
568584
return self._to_human(unit_list)
569-
570-
571-
# for current fn name, specify 0 or no argument.
572-
# for name of caller of current func, specify 1.
573-
# for name of caller of caller of current func, specify 2. etc.
574-
# Balantly copied from https://stackoverflow.com/a/31615605/2635443
575-
fn_name = lambda n=0: sys._getframe(n + 1).f_code.co_name

0 commit comments

Comments
 (0)