A code illustration as an intro to my questions: import re, inspect, datetime inspect.getargspec (re.findall) # => # ArgSpec(args = ['pattern', 'string', 'flags'], varargs=None, # keywords=None, defaults = (0,)) type (datetime.datetime.replace) # =>
The following useful decorator measures the execution time of a function. It also prints the function's name. However, it would be great if it could also print the class name if the function is a method. What is a concise way to get to the full metho
I have an array named as joinedArray. In one case, it has the value [undefined, undefined]. I have written one if condition like: if(joinArray === undefined){ vm.selectedFriends = []; angular.forEach($scope.contacts, function(contact){ if (contact.se
Can a Google Apps script learn its own name? or its id? Can it get the id of its containing folder? Can it learn where it resides in the folder hierarchy? Can script "A" get/set the properties of script "B"? Can script "A" ed
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_unbound_method(MyClass().bar) == False is_unbound_method(MyClass.b
I am confused about the difference between observer design pattern and introspection in php. for example the function class_exists() – it checks whether a class has been defined - is an introspection function. So is it an example of observer design p
Hi still learn some concepts in java. so sorry if this is a silly question I Have a class in a jar. i am loading it to my class path dynamically using reflection. and then i am calling the classes constructor method like so : File jar = new File("C:\
Are there introspection techniques in C++ like those in python? For example: I want to get more information about a specific object without going through the header file or referring back to cpp reference. Am I asking a proper question, or moving the
Hello all :) I'm trying to chose the right constructor in a class. Here is the code: Constructor[] constructors = targetClass.getConstructors(); Constructor goodConstructor = null; for (Constructor constructor : constructors) { Class[] parameterTypes
I need to get the type of the item of a collection. For retrieving the class of a single instance I use the following code: classUnderTest.getName() But, how can I retrieve the class of the items of the following collection? Collection collection = (
I'm writing a python (3.2+) plugin library and I want to create a function which will create some variables automatically handled from config files. The use case is as follows (class variable): class X: option(y=0) def __init__(self): pass (instance
I'm looking for something similar to attributes in Java, to use in an objective-c environment. Suppose I have an implementation file with a bunch of methods defined. Is there any way I can mark them up such that I could find them with introspection a
In some circumstances, I want to print debug-style output like this: # module test.py def f() a = 5 b = 8 debug(a, b) # line 18 I want the debug function to print the following: debug info at test.py: 18 function f a = 5 b = 8 I am thinking it should
This is primarily a curiosity, I'm not really sure what's the practical use of this but here goes. Since blocks are also Objective-C objects, is it possible to check their type? That is, does it respond to the isKindOfClass: message and how to use th
Is it possible to write a function arity :: a -> Integer to determine the arity of arbitrary functions, such that > arity map 2 > arity foldr 3 > arity id 1 > arity "hello" 0 ?It's easy with OverlappingInstances: {-# LANGUAGE Flex
I have a Java object obj that has attributes obj.attr1, obj.attr2 etc. The attributes are possibly accessed through an extra level of indirection: obj.getAttr1(), obj.getAttr2(), if not public. The challenge: I want a function that takes an object, a
I'm currently trying to roll my own "marshal" code for python so i can store compiled python code on Google App Engine to serve scripts on a dynamic way. As you all can verify, "marshal" isn't supported on GAE and "pickle" ca
Lately I wrote an application in java (for android) which used reflection to invoke methods of some objects. The argument number and type was unknown, meaning, I had a unified mechanism that received an object name, method name and array of parameter
suppose i have a class Foo and an instance of this class myFoo: Foo *myFoo; is there any method "dispalyFooObjectName" that can display the name of the object, for exmample : NSLog(@"i was called from %s", [myFoo dispalyFooObjectName])
In Python, without using the traceback module, is there a way to determine a function's name from within that function? Say I have a module foo with a function bar. When executing foo.bar(), is there a way for bar to know bar's name? Or better yet, f
I'm currently busy making a Python ORM which gets all of its information from a RDBMS via introspection (I would go with XRecord if I was happy with it in other respects) - meaning, the end-user only tells which tables/views to look at, and the ORM d
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 writ
I use this pattern to test for undefined and null values in ActionScript/Flex : if(obj) { execute() } Unfortunately, a ReferenceError is always thrown when I use the pattern to test for child objects : if(obj.child) { execute() } ReferenceError: Erro
I want to see the inner constructs of a special view on Mac, like the class name and hierarchy, etc. On Windows, we can use the Spy app for this purpose. Is there any app that works similarly for use on the Mac ?Yes, you're looking for F-Script. Have
Is there any way to get the name of an object in Python? For instance: my_list = [x, y, z] # x, y, z have been previously defined for bla in my_list: print "handling object ", name(bla) # <--- what would go instead of `name`? # do something t
I have came up with this: [a for a in dir(__builtins__) if str(type(getattr(__builtins__,a))) == "<type 'builtin_function_or_method'>"] I know its ugly. Can you show me a better/more pythonic way of doing this?There is the inspect module:
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: from datetime import date, datetime def test(): retu
Is it possible to retrieve the names of all procedures and functions that reside within a particular package? I understand that they can be gleaned (smells hack-ish) from the ALL_SOURCE view, but I would prefer a more canonical strategy.DBA_PROCEDURE
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' inside the Python objects to see how they tick - like their
Say you have a javascript object like this: var data = { foo: 'bar', baz: 'quux' }; You can access the properties by the property name: var foo = data.foo; var baz = data["baz"]; But is it possible to get these values if you don't know the name