introspection

Is it possible to get the function name from the mangled string

送分小仙女□ 提交于 2019-12-25 18:24:48
问题 This question is a continuation of the following question, where a code to demangle a function-name given by the backtrace function is presented. I wonder whether there is a way to get the name and the namespaces of a callable object . Here we assume that the function does have a name and that it is possible to demangle its name with abi::__cxa_demangle (for example, it's not a lambda function). Furthermore, would it be possible to get a list of the namespaces in which the function is? 来源:

Find name of dynamic method in Python

纵然是瞬间 提交于 2019-12-25 05:59:25
问题 I want to proxy an API over a network. I have the API in a dictionary. I'd like to create a class with the API methods from the dictionary so I can use the API as if I was local. The trouble is finding the name of my dynamically created method. (My approach is based on Adding a Method to an Existing Object and Python dynamic class methods.) class MainClass(object): def build_API(self): methods = dict(meth1='arg1', meth2='arg2') for key in methods.iterkeys(): setattr(self, key, MethodType(self

Find name of dynamic method in Python

半腔热情 提交于 2019-12-25 05:58:05
问题 I want to proxy an API over a network. I have the API in a dictionary. I'd like to create a class with the API methods from the dictionary so I can use the API as if I was local. The trouble is finding the name of my dynamically created method. (My approach is based on Adding a Method to an Existing Object and Python dynamic class methods.) class MainClass(object): def build_API(self): methods = dict(meth1='arg1', meth2='arg2') for key in methods.iterkeys(): setattr(self, key, MethodType(self

Swift 2 - Check Type of empty Array (Introspection)

只愿长相守 提交于 2019-12-24 14:04:50
问题 I'm currently working on introspection in Swift 2 and have Problems getting the specific type for an Array (in this example an Array<String> ). var prop = obj.valueForKey("strings")! if prop is Array<String> { println("true") } if prop is Array<Int> { println("true") } Output is: true true while it should be true false Is there a way to find out the type for the members of the Array? For example, if I daclared the Array as Array<String> I want to get String or at least be able to check if it

Lowlevel introspection in python3?

泪湿孤枕 提交于 2019-12-23 12:04:37
问题 Is there some introspection method allowing to reliably obtain the underlying data structure of an object instance, that is unaffected by any customizations? In Python 3 an object's low-level implementation can be deeply obscured: Attribute lookup can be customized, and even the __dict__ and __slots__ attributes may not give a full picture, as they are writeable. dir() is explicitly meant to show "interesting" attributes rather than actual attributes, and even the inspect module doesn't seem

Using Cairo Regions in python with gi.repository

こ雲淡風輕ζ 提交于 2019-12-23 10:07:37
问题 I can't seem to get cairo regions working in within using the gintrospection. For example from gi.repository import cairo reg = cairo.Region() will give me Traceback (most recent call last): File "<stdin>", line 1, in <module> MemoryError and trying to get a region from Gdk.get_clip_region() will give me return info.invoke(*args) TypeError: Couldn't find conversion for foreign struct 'cairo.Region' What obvious thing am I missing? I can't find a way to iniatilize the library, and can't

add methods in subclasses within the super class constructor

妖精的绣舞 提交于 2019-12-22 18:05:29
问题 I want to add methods (more specifically: method aliases) automatically to Python subclasses. If the subclass defines a method named 'get' I want to add a method alias 'GET' to the dictionary of the subclass. To not repeat myself I'd like to define this modifation routine in the base class. But if I check in the base class __init__ method, there is no such method, since it is defined in the subclass. It will become more clear with some source code: class Base: def __init__(self): if hasattr

How can I tell java.beans.Introspector to ignore a getter method?

我的梦境 提交于 2019-12-22 12:16:01
问题 I have one field which is a composition of two values. This is the field that gets serialized to/from JSON and works great. public String getRevisions() { return revisions; } public void setRevisions(String revisions) { this.revisions = revisions; } I added two helper methods to retrieve the separate values, but I don't want them serialized to JSON. public String getCurrentRevision() { ... return first revision ... } public String getPreviousRevision() { ... return second revision ... } Is

Tools for merging java beans

人走茶凉 提交于 2019-12-22 10:18:21
问题 It's easy to merge two simple, flat java beans using introspection: BeanInfo info = Introspector.getBeanInfo( ContactBean.class ); PropertyDescriptor pDescArr[] = info.getPropertyDescriptors(); for(PropertyDescriptor pDesc : pDescArr){ //copy properties and check for conflicts here } However, it gets a little more complicated when the properties contain nested beans, or collections. Is there a smart tool somewhere which will handle a deep merge of complex beans? Some more specifics on just

How do I get the string representation of a variable in python?

五迷三道 提交于 2019-12-22 06:11:26
问题 I have a variable x in python. How can i find the string 'x' from the variable. Here is my attempt: def var(v,c): for key in c.keys(): if c[key] == v: return key def f(): x = '321' print 'Local var %s = %s'%(var(x,locals()),x) x = '123' print 'Global var %s = %s'%(var(x,locals()),x) f() The results are: Global var x = 123 Local var x = 321 The above recipe seems a bit un-pythonesque. Is there a better/shorter way to achieve the same result? 回答1: Q: I have a variable x in python. How can i