From ddfb500fa21d9767d2132f939f6ae28d23611c3b Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Thu, 24 Oct 2019 18:45:05 +0200 Subject: [PATCH] Add misc.object_builtin_name() object_builtin_name() is meant to derive an object name from its class name. Doesn't work well, but adding the code nonetheless for improving it later. Signed-off-by: Jan Lindemann --- tools/python/jwutils/misc.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/tools/python/jwutils/misc.py b/tools/python/jwutils/misc.py index 9ad44e4..8800211 100644 --- a/tools/python/jwutils/misc.py +++ b/tools/python/jwutils/misc.py @@ -37,4 +37,13 @@ def atomic_store(contents, path): # export os.rename(name, path) _tmpfiles.remove(name) +# see https://stackoverflow.com/questions/2020014 +def object_builtin_name(o, full=True): # export + #if not full: + # return o.__class__.__name__ + module = o.__class__.__module__ + if module is None or module == str.__class__.__module__: + return o.__class__.__name__ # Avoid reporting __builtin__ + return module + '.' + o.__class__.__name__ + atexit.register(_cleanup)