Questions tagged [inspect]

DO NOT USE! THIS IS AMBIGUOUS. You might be looking for [web-inspector].

610 questions
578
votes
20 answers

How to list all functions in a module?

I have a Python module installed on my system and I'd like to be able to see what functions/classes/methods are available in it. I want to call the help function on each one. In Ruby I can do something like ClassName.methods to get a list of all the…
Chris Gow
  • 7,514
  • 4
  • 23
  • 18
411
votes
13 answers

How can I get a list of all classes within current module in Python?

I've seen plenty of examples of people extracting all of the classes from a module, usually something like: # foo.py class Foo: pass # test.py import inspect import foo for name, obj in inspect.getmembers(foo): if inspect.isclass(obj): …
mcccclean
  • 7,721
  • 10
  • 32
  • 36
185
votes
9 answers

How can I read a function's signature including default argument values?

Given a function object, how can I get its signature? For example, for: def my_method(first, second, third='something'): pass I would like to get "my_method(first, second, third='something')".
Spì
  • 2,115
  • 2
  • 15
  • 10
185
votes
12 answers

"Inspect" a hover element?

Note: I've read similar threads, but none quite my issue - I can right click on it fine, it just then disappears. I find 'Inspect Element' an invaluable tool in Chrome, however I'm having trouble using it for sub-menu for an element on my nav bar,…
OJFord
  • 10,522
  • 8
  • 64
  • 98
105
votes
8 answers

How to inspect Javascript Objects

How can I inspect an Object in an alert box? Normally alerting an Object just throws the nodename: alert(document); But I want to get the properties and methods of the object in the alert box. How can I achieve this functionality, if possible? Or…
Valentina
  • 1,053
  • 2
  • 8
  • 5
101
votes
4 answers

How to use inspect to get the caller's info from callee in Python?

I need to get the caller info (what file/what line) from callee. I learned that I can use inpect module for that for purposes, but not exactly how. How to get those info with inspect? Or is there any other way to get the info? import inspect print…
prosseek
  • 182,215
  • 215
  • 566
  • 871
99
votes
12 answers

Using a dictionary to select function to execute

I am trying to use functional programming to create a dictionary containing a key and a function to execute: myDict={} myItems=("P1","P2","P3",...."Pn") def myMain(key): def ExecP1(): pass def ExecP2(): pass def…
JohnnyDH
  • 2,015
  • 2
  • 17
  • 12
97
votes
7 answers

How to get all methods of a Python class with given decorator?

How to get all methods of a given class A that are decorated with the @decorator2? class A(): def method_a(self): pass @decorator1 def method_b(self, b): pass @decorator2 def method_c(self, t=5): pass
kraiz
  • 2,178
  • 1
  • 22
  • 22
70
votes
7 answers

Debugging: Get filename and line number from which a function is called?

I'm currently building quite a complex system in Python, and when I'm debugging I often put simple print statements in several scripts. To keep an overview I often also want to print out the file name and line number where the print statement is…
kramer65
  • 50,427
  • 120
  • 308
  • 488
52
votes
2 answers

What is the difference between a stack and a frame?

Under what situations would I want to use one over the other? What is the difference between: >>> import inspect >>> print(inspect.getouterframes(inspect.currentframe())) [(, '', 1, '', None,…
jmunsch
  • 22,771
  • 11
  • 93
  • 114
49
votes
6 answers

How to debug webview remotely?

How can I do debug/inspect element of apk webview. I have tried this but it is helpful only for chrome not for apk. Please suggest me
Kundan Atre
  • 3,853
  • 5
  • 26
  • 39
40
votes
6 answers

Inspect python class attributes

I need a way to inspect a class so I can safely identify which attributes are user-defined class attributes. The problem is that functions like dir(), inspect.getmembers() and friends return all class attributes including the pre-defined ones like:…
Jakob Simon-Gaarde
  • 443
  • 1
  • 4
  • 6
39
votes
4 answers

Get full package module name

For verbose debug messages in my application I'm using a function that returns a helpful prefix. Consider the following example: import inspect def get_verbose_prefix(): """Returns an informative prefix for verbose debug output messages""" …
Hubro
  • 56,214
  • 69
  • 228
  • 381
36
votes
7 answers

Get current function name from inside that function using Python

I want to log all the names of functions where my code is going. It does not matter who is calling the function. import inspect def whoami(): return inspect.stack()[1][3] def foo(): print(whoami()) Currently it prints foo. I want it to…
John Kaff
  • 1,905
  • 6
  • 18
  • 30
26
votes
5 answers

How to move the CSS Styles part to the bottom in Chrome Devtools?

When i go to Inspect on Google Chrome, i have the HTML and CSS sections in parallel as shown below. How can i move the CSS part to the bottom while keeping the HTML part above, as shown below?
Moudinho
  • 309
  • 4
  • 6
1
2 3
40 41