introspection

List classes in directory (Python)

I'm developing a Python 2.6 package in which I would like to fetch a list of all classes in a certain directory (within the package) in order to then perform introspection on the class objects. Specifically, if the directory containing the currently executing module has a sub-dir called 'foobar' and 'foobar' contains .py files specifyin...

How can a program on Linux introspect its pid?

How can a program on Linux discover the process id of itself? Is there something in /proc/self that will do the trick? ...

Introspection to get decorator names on a method?

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. ...

python introspection - how to detect the object i am in

Suppose I have a free function which has been called from a class method. Is there a way for me to introspect the call stack in the free function and determine what object called me? def foo(arg1) : s = ? #Introspect call stack and determine what object called me # Do something with s Thanks! ...

How can I get fields in an original order?

I have a code like: class Ordered(object): x = 0 z = 0 b = 0 a = 0 print(dir(Ordered)) it prints: [ ......., a, b, x, z] How can I get fields in an original order: x, z, b, a? I've seen similar behavior in Django Models. ...

Recursively walking a Python inheritance tree at run-time

Hi, I'm writing some serialization/deserialization code in Python that will read/write an inheritance hierarchy from some JSON. The exact composition will not be known until the request is sent in. So, I deem the elegant solution to recursively introspect the Python class hierarchy to be emitted and then, on the way back up through the ...

Is it common/good practice to test for type values in Python?

Hello guys and gals, Is it common in Python to keep testing for type values when working in a OOP fashion? class Foo(): def __init__(self,barObject): self.bar = setBarObject(barObject) def setBarObject(barObject); if (isInstance(barObject,Bar): self.bar = barObject else: # throw ...

Finding what list a class instance is in, in Python.

This problem is thus: I have an instance of a class, I want to know what list it is a part of, i.e. : class test_class() : def test() : print 'I am a member of list', parent_list foo = [test_class(), 52, 63] bar = ['spam', 'eggs'] foo[0].test() I would like to print out I am a member of list foo. There are an arbitrary nu...

Dynamic Class Instantiation in Python

I have a bunch of classes in a module. Let's say: '''players.py''' class Player1: def __init__(self, name='Homer'): self.name = name class Player2: def __init__(self, name='Barney'): self.name = name class Player3: def __init__(self, name='Moe'): self.name = name ... Now, in another module, I w...

How to organise the file structure of my already working plugin system?

I am working on a project whose main design guiding principle is extensibility. I implemented a plugin system by defining a metaclass that register - with a class method - the class name of any plugin that gets loaded (each type of plugin inherit from a specific class defined in the core code, as there are different types of plugins in ...

Java object graph visitor library

Do you know a good java object graph visitor library? I want to visit an object and its sub components and perform some actions when some conditions are matched. Example usage: on a huge domain object graph, reset each id to null on a huge domain object graph, replace each Set with a TreeSet instance containing the same elements. ...

SQLAlchemy introspection of declarative classes

I'm writing a small sqlalchemy shim to export data from a MySQL database with some lightweight data transformations—mostly changing field names. My current script works fine but requires me to essentially describe my model twice—once in the class declaration and once as a list of field names to iterate over. I'm trying to figure out ...

Python introspection: description of the parameters a function takes.

Hello, I'm wondering if there is a tool similar to dir() for modules that will tell me what parameters a given function takes. For instance, I would like to do something like dir(os.rename) and have it tell me what the parameters are documented as so that I can avoid checking the documentation online, and instead use only the python...

Ruby on Rails: how do I check if a variable in an instance of a class?

In Java, you can do instanceof. Is there a Ruby equivalent? ...

Predicate's label in JSF on Nuxeo.

Hi everyone. I'am on a JSF problem using Nuxeo : I would like to get a predicate label (like "label.relation.predicate.inverse.Requires") out of this very predicate inside a JSF. I tried to do many things and all the objects I have are "statement" and "node". I tried to figure the label from the "#{statement.predicate.uri}" and wethe...

Illegal access exception when trying to access attibrute from parent class by introspection

Hi, I am currently playing with introspection and annotations in Java 1.5. The have a parent abstract class AbstractClass. The inherited classes can have attributes (of type ChildClass) annotated with a custom @ChildAttribute annotation. I wanted to write a generic method that would list all @ChildAttribute attributes of an instance. ...

Can a LabVIEW VI tell whether one of its output terminals is wired?

In LabVIEW, is it possible to tell from within a VI whether an output terminal is wired in the calling VI? Obviously, this would depend on the calling VI, but perhaps there is some way to find the answer for the current invocation of a VI. In C terms, this would be like defining a function that takes arguments which are pointers to wher...

Fooling Ruby's case operator, ===, with proxy objects

I'm trying to make a proxy object that transfers almost all method calls to a child object, essentially the delegator pattern. For the most part, I'm just using a BasicObject and passing every call with method_missing to the child object. So far, so good. The trick is that try as I might, I can't fool Ruby's case operator, so I can't ...

Why does a meta class change the way issubclass() work?

OK, so I'm writing a framework that looks for python files in sub directories that are named task.py and then look for classes that are derived from the base class Task and collect them. I decided that I needed to add a meta class to Task, but then the issubclass() started to behave in a weird way. Here is how the directory layout looks:...

How to get the arity of a method?

In Javascript, for example, you can get the arity (the number of arguments a function is supposed to take) by simply func.length. How can I get this information for a method in Objective-C? ...