Get __name__ of calling function’s module in Python
Suppose myapp/foo.py contains:
Suppose myapp/foo.py contains:
Given a class Foo (whether it is a new-style class or not), how do you generate all the base classes – anywhere in the inheritance hierarchy – it issubclass of?
Is there a way to get all attributes/methods/fields/etc. of an object in Python? vars() is close to what I want, but it doesn’t work unless an object has a __dict__, which isn’t always true (e.g. it’s not true for a list, a dict, etc.). Answers: Thank you for visiting the Q&A section on Magenaut. Please … Read more
How can I get a variable that contains the currently executing function in Python? I don’t want the function’s name. I know I can use inspect.stack to get the current function name. I want the actual callable object. Can this be done without using inspect.stack to retrieve the function’s name and then evaling the name to get the callable object?
I have a dict, which I need to pass key/values as keyword arguments.. For example..
class C(object): def f(self): print self.__dict__ print dir(self) c = C() c.f() output: {} ['__class__', '__delattr__','f',….] why there is not a ‘f’ in self.__dict__ Answers: Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If … Read more
I am trying to figure out how to get the names of all decorators on a method. I can already get the method name and docstring, but cannot figure out how to get a list of decorators.