introspection

Getting object name in Objective-c

为君一笑 提交于 2019-12-10 19:29:12
问题 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]); and the result will be : i was called from myFoo 回答1: In most programming languages objects don't have names. Just because some variable myFoo references your object, doesn't mean that your object is "called" myFoo . And in most C-based languages variable

How to determine the Java byte code version of the current class programatically? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-12-10 16:54:58
问题 This question already has answers here : Java API to find out the JDK version a class file is compiled for? (8 answers) Closed 6 years ago . I have a situation where the deployment platform is Java 5 and the development happens with Eclipse under Java 6 where we have established a procedure of having a new workspace created when beginning work on a given project. One of the required steps is therefore setting the compiler level to Java 5, which is frequently forgotten. We have a test machine

Why does `instance_of_object.foo is instance_of_object.foo` evaluate False? [duplicate]

感情迁移 提交于 2019-12-10 14:26:00
问题 This question already has an answer here : Two methods inherited from one method in class are different in instances, aren't they? (1 answer) Closed last year . If I have a class A: def foo(self): pass this evaluates to True : getattr(A, 'foo') is A.foo but this evaluates to False : a = A() getattr(a, 'foo') is a.foo as does a.foo is a.foo Why? I found that getattr(a, 'foo') and a.foo both are represented by <bound method A.foo of <__main__.A object at 0x7a2c4de10d50>>) So no hint there....

Glassfish - JEE6 - Use of Interceptor to measure performance

只谈情不闲聊 提交于 2019-12-10 11:29:06
问题 For measuring execution time of methods, I've seen suggestions to use public class PerformanceInterceptor { @AroundInvoke Object measureTime(InvocationContext ctx) throws Exception { long beforeTime = System.currentTimeMillis(); Object obj = null; try { obj = ctx.proceed(); return obj; } finally { time = System.currentTimeMillis() - beforeTime; // Log time } } Then put @Interceptors(PerformanceInterceptor.class) before whatever method you want measured. Anyway I tried this and it seems to

How to obtain all instances of a class within the current module

一曲冷凌霜 提交于 2019-12-10 09:41:06
问题 I have a module foo that defines a class Foo , and instantiates a number of instances of this class. From other modules, I can import foo and obtain a list of the Foo objects instantiated by: [getattr(foo,f) for f in dir(f) if isinstance(getattr(foo,f), foo.Foo)] It would be convenient if I could do this from within the module foo . But as written, the name foo is meaningless inside foo , and changing to self doesn't help. Is there a way to use introspection within this module to find all

Pytest - Fixture introspect on function level

我与影子孤独终老i 提交于 2019-12-10 09:39:01
问题 I've got a fixture that requires a variable from the test function. Using introspection and declaring the variable in the function namespace/context should work if introspection on function level works, as it does for module level, but each time I run the code I end up with None instead of the string "Fancy Table". In the fixture I set the scope to 'function' and then introspect via getattr and request.function: #conftest.py @pytest.fixture(scope='function') def table(request): from data

How to detect at runtime whether symbols are stripped?

隐身守侯 提交于 2019-12-09 09:50:07
问题 In my C++ program, how can I detect programmatically at runtime whether symbols have been stripped via the 'strip' gnu development tool on Linux? I'd like a function definition which returns true if stripped, otherwise false. Would using dlsym() on "main()" work to detect this reliably? 回答1: I know the file command can tell the difference, so you could possibly look at its source to see what mechanism it uses. 回答2: From a comment left for another answer: A stripped ELF will lack a .symtab

How to find out in Vim which command is triggered by some shortcut

隐身守侯 提交于 2019-12-09 06:36:24
问题 I try to execute a command in some plugin by pushing it's keyboard shortcut F2 . But some other command is executed, instead. But that command gives an error. So it is not clear where the key mapping of that interfering command is defined. I want to change the mapping of that shortcut. To do this I need to find out what that interfering command is. Is there a way to find out which command is triggered by some keyboard shortcut? 回答1: verbose map <F2> will give you information about both {rhs}

Ruby on Rails: how to check pluralized and single form of names

浪尽此生 提交于 2019-12-08 18:58:46
问题 I have created a model Anonymous with command rails g model Anonymous section_id:integer aid:string fake:bool active:bool but table name in the migration is called anonymous class CreateAnonymous < ActiveRecord::Migration def change create_table :anonymous do |t| t.integer :section_id t.string :aid t.bool :fake t.bool :active t.timestamps end end end Am i right that pluralized form of Anonymous is Anomymous too ? (English is not my native language). How can i see what pluralized names Rails

Pythonic way to find the name of global namespace imports

梦想与她 提交于 2019-12-08 11:58:11
问题 I am trying to build some dynamic code that parses a text file with objects named from the imports at the top of the module... right now I iterate through all items in sys._getframe(0) to find f_globals . Is there a more pythonic way of finding f_globals ? import re import sys import inspect ## Import all Object models below from Models.Network.Address import MacAddress as _MacAddress from Models.Network.Address import Ipv4Address as _Ipv4Address class Objects(object): "Define a structure for