Classes
toolbox_python.classes
🔗
Summary
The classes
module is designed for functions to be executed on classes; not within classes.
For any methods/functions that should be added to classes, you should consider re-designing the original class, or sub-classing it to make further alterations.
get_full_class_name
🔗
get_full_class_name(obj: Any) -> str
Summary
This function is designed to extract the full name of a class, including the name of the module from which it was loaded.
Details
Note, this is designed to retrieve the underlying class name of an object, not the instance name of an object. This is useful for debugging purposes, or for logging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj
|
Any
|
The object for which you want to retrieve the full name. |
required |
Returns:
Type | Description |
---|---|
str
|
The full name of the class of the object. |
Examples
Set up | |
---|---|
1 |
|
Example 1: Check the name of a standard class | |
---|---|
1 |
|
str
Conclusion: Successful class name extraction.
Example 2: Check the name of an imported class | |
---|---|
1 2 |
|
random.Random
Conclusion: Successful class name extraction.
Credit
Full credit goes to:
https://stackoverflow.com/questions/18176602/how-to-get-the-name-of-an-exception-that-was-caught-in-python#answer-58045927
Source code in src/toolbox_python/classes.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
|