inspect

What is the difference between a stack and a frame?

无人久伴 提交于 2019-11-27 09:23:49
问题 Under what situations would I want to use one over the other? What is the difference between: >>> import inspect >>> print(inspect.getouterframes(inspect.currentframe())) [(<frame object at 0x8fc262c>, '<stdin>', 1, '<module>', None, None)] And: >>> import traceback >>> traceback.extract_stack() [('<stdin>', 1, '<module>', None)] Update: Another: >>> import sys >>> print(sys._getframe().f_trace,sys._getframe().f_code) (None, <code object <module> at 0x8682a88, file "<stdin>", line 1>) I do

HTML Render with inspect element functionality? HOW TO C#

扶醉桌前 提交于 2019-11-27 08:09:59
问题 I want to do a HTML Render that shows a HTML Document, not necessary an online webpage. Then when I click over a HTML Control, it shows only the HTML where I clicked. The real intention is to get the xpath from the root element to the selected TAG. 回答1: I think that you must use System.Windows.Forms.WebBrowser control for loading your html document. Override for example OnLeftButton event of the Form. And then call WebBrowser.Document.GetElementFromPoint method. So this method will return

Introspecting a given function's nested (local) functions in Python

杀马特。学长 韩版系。学妹 提交于 2019-11-27 07:07:22
问题 Given the function def f(): x, y = 1, 2 def get(): print 'get' def post(): print 'post' is there a way for me to access its local get() and post() functions in a way that I can call them? I'm looking for a function that will work like so with the function f() defined above: >>> get, post = get_local_functions(f) >>> get() 'get' I can access the code objects for those local functions like so import inspect for c in f.func_code.co_consts: if inspect.iscode(c): print c.co_name, c which results

Howto get all methods of a python class with given decorator

拜拜、爱过 提交于 2019-11-27 06:06:29
How to get all methods of a given class A that are decorated with the @decorator2? class A(): def method_a(self): pass @decorator1 def method_b(self, b): pass @decorator2 def method_c(self, t=5): pass ninjagecko Method 1: Basic registering decorator I already answered this question here: Calling functions by array index in Python =) Method 2: Sourcecode parsing If you do not have control over the class definition , which is one interpretation of what you'd like to suppose, this is impossible (without code-reading-reflection), since for example the decorator could be a no-op decorator (like in

【原创】响应式设计之移动端调试工具

元气小坏坏 提交于 2019-11-27 05:14:40
背景 2013年是网页设计响应式的一年。所谓响应式网页设计,是由Ethan Marcotte在2010年提出的名词,指可以自动识别屏幕宽度、并做出相应调整的网页设计。简单来说就是同一张网页自动适应不同大小的屏幕,根据屏幕宽度,自动调整布局。这是一个多么强大的概念,一套代码兼容所有设备,节省维护成本,提高开发效率。然而,现实并非如此完美,在其强大的背后也有鲜为人知的辛酸苦楚。 众所周知,在响应式设计出现或者说在各种移动设备不断迅速抢占PC市场之前,所有的网页设计几乎不要求兼容移动设备,而在PC端的开发调试已经相当成熟,各种调试工具纷纷脱颖而出,诸如:Firebug、Chrome开发者工具等。这让开发者如鱼得水,在传统网页设计中游刃有余。 而如今的互联网市场已经有很大一部分属于移动设备的领地,网页设计兼容移动设备刻不容缓,而响应式设计的提出让这一目标成为可能,甚至可以说是网页设计兼容移动设备的完美解决方案。但是,光有方案只能是空谈,几乎没有人能够不经过反复调试就能写出完全正确的代码,移动设备上的开发调试给网页设计带来了阻力,让开发者不得不投入更多的成本用以对移动设备兼容的调试。所以良好的移动开发调试工具必须问世,而拥有一款优秀的移动开发调试工具,必然给响应式网页设计锦上添花。 人类的智慧是无穷的,2010年底weinre问世,至今weinre已经发布2.0.0版本

Using a dictionary to select function to execute

五迷三道 提交于 2019-11-27 00:20:34
I am trying to use functional programming to create a dictionary containing a key and a function to execute: myDict={} myItems=("P1","P2","P3",...."Pn") def myMain(key): def ExecP1(): pass def ExecP2(): pass def ExecP3(): pass ... def ExecPn(): pass Now, I have seen a code used to find the defined functions in a module, and I need to do something like this: for myitem in myItems: myDict[myitem] = ??? #to dynamically find the corresponding function So my question is, How do I make a list of all the Exec functions and then assign them to the desired item using the a dictionary? so at the end I

How to inspect Javascript Objects

。_饼干妹妹 提交于 2019-11-26 23:55:31
问题 How can I inspect an Object in an alert box? Normally alerting an Object just throws the nodename: alert(document); But I want to get the properties and methods of the object in the alert box. How can I achieve this functionality, if possible? Or are there any other suggestions? Particularly, I am seeking a solution for a production environment where console.log and Firebug are not available. 回答1: The for - in loops for each property in an object or array. You can use this property to get to

How can I programmatically change the argspec of a function in a python decorator?

心已入冬 提交于 2019-11-26 23:34:33
问题 Given a function: def func(f1, kw='default'): pass bare_argspec = inspect.getargspec(func) @decorator def func2(f1, kw='default'): pass decorated_argspec = inspect.getargspec(func2) How can I create a decorator such that bare_argspec == decorated_argspec ? (As to why, the framework that calls the decorated function does argspec inspection to choose what to pass in, so the decorator has to retain the same argspec in order to play nice. When I posed this question on #python, I got a long speech

Can a Python method check if it has been called from within itself?

走远了吗. 提交于 2019-11-26 23:10:28
问题 Let's say I have a Python function f and fhelp . fhelp is designed to call itself recursively. f should not be called recursively. Is there a way for f to determine if it has been called recursively? 回答1: Use the traceback module for this: >>> import traceback >>> def f(depth=0): ... print depth, traceback.print_stack() ... if depth < 2: ... f(depth + 1) ... >>> f() 0 File "<stdin>", line 1, in <module> File "<stdin>", line 2, in f None 1 File "<stdin>", line 1, in <module> File "<stdin>",

Inspect python class attributes

感情迁移 提交于 2019-11-26 22:21:17
问题 I need a way to inspect a class so I can safely identify which attributes are user-defined class attributes. The problem is that functions like dir(), inspect.getmembers() and friends return all class attributes including the pre-defined ones like: __class__ , __doc__ , __dict__ , __hash__ . This is of course understandable, and one could argue that I could just make a list of named members to ignore, but unfortunately these pre-defined attributes are bound to change with different versions