How to get the caller class name inside a function of another class in python?

Well, after some digging at the prompt, here’s what I get: stack = inspect.stack() the_class = stack[1][0].f_locals[“self”].__class__.__name__ the_method = stack[1][0].f_code.co_name print(“I was called by {}.{}()”.format(the_class, the_method)) # => I was called by A.a() When invoked: ➤ python test.py A.a() B.b() I was called by A.a() given the file test.py: import inspect class A: def a(self): … Read more

Can a program depend on a library during compilation but not runtime?

A compile-time dependency is generally required at runtime. In maven, a compile scoped dependency will be added to the classpath on runtime (e.g. in wars they will be copied to WEB-INF/lib). It is not, however, strictly required; for instance, we may compile against a certain API, making it a compile-time dependency, but then at runtime … Read more

Runtime.exec on argument containing multiple spaces

Ok, this is not simply an update but also an answer so I’m filing it as one. According to all information I could find, the following should theoretically do it: String[] cmd = {“explorer.exe”, “/select,\”C:\New”, “”, “”, “”, “”, “”, “”, “Folder\file.txt\””}; The multiple spaces have been broken into empty strings and the array version … Read more