introspection Questions

7

Solved

What is the equivalent of Linux's /proc/cpuinfo on FreeBSD v8.1? My application reads /proc/cpuinfo and saves the information in the log file, what could I do to get similar information logged on F...
Maghutte asked 3/11, 2010 at 2:39

2

Solved

I am looking to do something similar to what was asked here Getting list of parameter names inside python function, but using partial functions. ie. I need to get the possible arguments for a parti...
Rompish asked 23/5, 2011 at 13:20

11

Solved

I'm trying to write some code in bash which uses introspection to select the appropriate function to call. Determining the candidates requires knowing which functions are defined. It's easy to lis...
Abeyta asked 12/4, 2010 at 22:3

10

Solved

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.
Schmeltzer asked 12/7, 2010 at 20:30

7

Solved

Is there a straightforward way to find all the modules that are part of a python package? I've found this old discussion, which is not really conclusive, but I'd love to have a definite answer befo...
Valued asked 10/11, 2009 at 12:47

29

I'm starting to code in various projects using Python (including Django web development and Panda3D game development). To help me understand what's going on, I would like to basically 'look' insi...
Lithe asked 17/6, 2009 at 10:17

13

Solved

Given a Django model, I'm trying to list all of its fields. I've seen some examples of doing this using the _meta model attribute, but doesn't the underscore in front of meta indicate that the _met...
Radiochemical asked 5/9, 2010 at 21:6

6

Solved

I'd like to get the name of the current Activity to be sent along in the URI of an HttpRequest. Is there a way to do this without referring specifically to the Activity? I know I can do myActivity...
Stillhunt asked 16/5, 2012 at 23:36

13

Solved

Python: How to get the caller's method name in the called method? Assume I have 2 methods: def method1(self): ... a = A.method2() def method2(self): ... If I don't want to do any change for...
Recollect asked 16/4, 2010 at 15:18

32

Solved

So what I'm looking for here is something like PHP's print_r function. This is so I can debug my scripts by seeing what's the state of the object in question.
Reprobation asked 10/10, 2008 at 16:19

6

Solved

Ok I know you can use the dir() method to list everything in a module, but is there any way to see only the functions that are defined in that module? For example, assume my module looks like this:...
Phares asked 9/7, 2009 at 22:49

4

Solved

Given a class C in Python, how can I determine which file the class was defined in? I need something that can work from either the class C, or from an instance of C. I am doing this because I am ge...
Pearson asked 30/3, 2009 at 13:58

7

Solved

I have a dict, which I need to pass key/values as keyword arguments.. For example.. d_args = {'kw1': 'value1', 'kw2': 'value2'} example(**d_args) This works fine, but if there are values in the ...
Protection asked 13/10, 2008 at 7:55

6

Solved

I've already seen the following question but it doesn't quite get me where I want: How can I get a list of all classes within current module in Python? In particular, I do not want classes that ar...
Twicetold asked 2/4, 2011 at 1:51

27

Solved

Is there a way to determine a function's name from within the function? def foo(): print("my name is", __myname__) # <== how do I calculate this at runtime? In the example above, the...
Preconscious asked 21/2, 2011 at 15:11

3

In PHP it is possible to get a full class name via class name resolution like this: Example: namespace Name\Space; class ClassName {} echo ClassName::class; Output: Name\Space\ClassName This is b...
Numbskull asked 17/2, 2021 at 9:5

2

Solved

I'd like to write a "toSource" function that will generate the source code for basic case classes. For example, I'd like: case class Person(name: String, age: Int) val bob = Person("Bob", 20) prin...
Engadine asked 30/10, 2012 at 23:11

6

Solved

Suppose o is a Python object, and I want all of the fields of o, without any methods or __stuff__. How can this be done? I've tried things like: [f for f in dir(o) if not callable(f)] [f for f i...
Bight asked 21/2, 2014 at 21:0

12

Solved

How do I find out the name of the class used to create an instance of an object in Python? I'm not sure if I should use the inspect module or parse the __class__ attribute.
Gualterio asked 4/2, 2009 at 11:37

3

Solved

I was just profiling my Python program to see why it seemed to be rather slow. I discovered that the majority of its running time was spent in the inspect.stack() method (for outputting debug messa...
Luftwaffe asked 1/7, 2013 at 14:38

7

Is there a way to print out a complete list of available members of a type or instance in Rust? For example: In Python, I can use print(dir(object)) In C, Clang has a Python API that can parse C...
Eclampsia asked 1/9, 2016 at 8:5

19

Solved

Given that a function a_method has been defined like def a_method(arg1, arg2): pass Starting from a_method itself, how can I get the argument names - for example, as a tuple of strings, like (&qu...
Qualified asked 20/10, 2008 at 14:22

4

This is the first example we meet when we face with decorators. But I'm not able to realize what exactly I would like. A simple decorator named LOG. It should work like this: @LOG def f(a, b=2, *...
Pyrope asked 30/10, 2009 at 9:2

4

Solved

def is_unbound_method(func): pass def foo(): pass class MyClass(object): def bar(self): pass What can I put in the body of is_unbound_method so that is_unbound_method(foo) == False is_unboun...
Caffeine asked 1/8, 2014 at 15:7

6

Solved

Is it possible to retrieve any class information from a frame object? I know how to get the file (frame.f_code.co_filename), function (frame.f_code.co_name) and line number (frame.f_lineno), but wo...
Synge asked 4/2, 2010 at 21:38

© 2022 - 2024 — McMap. All rights reserved.