|
15 | 15 |
|
16 | 16 | __intname__ = "ofunctions.misc" |
17 | 17 | __author__ = "Orsiris de Jong" |
18 | | -__copyright__ = "Copyright (C) 2014-2024 Orsiris de Jong" |
| 18 | +__copyright__ = "Copyright (C) 2014-2026 Orsiris de Jong" |
19 | 19 | __description__ = "Collection of various functions" |
20 | 20 | __licence__ = "BSD 3 Clause" |
21 | | -__version__ = "1.8.0" |
22 | | -__build__ = "2024042401" |
| 21 | +__version__ = "1.8.1" |
| 22 | +__build__ = "2026031001" |
23 | 23 | __compat__ = "python2.7+" |
24 | 24 |
|
25 | 25 |
|
|
37 | 37 |
|
38 | 38 | # Get current function name, can take int argument to get higher caller names |
39 | 39 | # 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 |
40 | 41 | fn_name = lambda n=0: sys._getframe(n + 1).f_code.co_name |
41 | 42 |
|
| 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 | + |
42 | 58 |
|
43 | 59 | def rot13(string): |
44 | 60 | # type: (str) -> str |
@@ -566,10 +582,3 @@ def human_bits(self): |
566 | 582 | def human_iec_bits(self): |
567 | 583 | unit_list = [unit for unit in self.bits_units if "i" in unit] |
568 | 584 | 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