introspection

How can I list the methods in a Python 2.5 module?

我是研究僧i 提交于 2019-12-03 09:12:43
问题 I'm trying to use a Python library written in C that has no documentation of any kind. I want to use introspection to at least see what methods and classes are in the modules. Does somebody have a function or library I can use to list the functions (with argument lists) and classes (with methods and member variables) within a module? I found this article about Python introspection, but I'm pretty sure it doesn't apply to Python 2.5. Thanks for the help. 回答1: Here are some things you can do at

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

爷,独闯天下 提交于 2019-12-03 08:04:51
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? verbose map <F2> will give you information about both {rhs} and place where this mapping was defined. For insert mode mappings replace map with imap , same for other

How do I inspect the methods of a Ruby object?

二次信任 提交于 2019-12-03 07:50:36
问题 I am wondering if there is a Ruby method call that shows only the methods defined by the Ruby object it's called from, as opposed to all the methods defined by its ancestor classes, which is what methods seems to do. 回答1: methods takes an optional boolean parameter, which specifies whether to also list the methods from the object's class and its superclasses or just the object's singleton methods. So you can do obj.methods(false) to only get the singleton methods defined on obj . If you want

What are the arguments to the types.CodeType() python call?

孤街醉人 提交于 2019-12-03 05:18:24
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" can't serialize code objects. I found out i can construct a code object with types.CodeType() but it expects 12 arguments. As much as i've tried, i can't find any documentation on this call and i really need to construct the code object so i can exec() it. My question is, does anyone know what are the parameters for this types.CodeType() "constructor" or any way to

How do I introspect things in Ruby?

泪湿孤枕 提交于 2019-12-03 04:53:54
问题 For instance, in Python, I can do things like this if I want to get all attributes on an object: >>> import sys >>> dir(sys) ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec

Inferring Spark DataType from string literals

我是研究僧i 提交于 2019-12-03 03:57:41
I am trying to write a Scala function that can infer Spark DataTypes based on a provided input string: /** * Example: * ======== * toSparkType("string") => StringType * toSparkType("boolean") => BooleanType * toSparkType("date") => DateType * etc. */ def toSparkType(inputType : String) : DataType = { var dt : DataType = null if(matchesStringRegex(inputType)) { dt = StringType } else if(matchesBooleanRegex(inputType)) { dt = BooleanType } else if(matchesDateRegex(inputType)) { dt = DateType } else if(...) { ... } dt } My goal is to support a large subset, if not all, of the available DataTypes

Haskell: Function to determine the arity of functions?

半世苍凉 提交于 2019-12-03 02:34:06
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 FlexibleInstances, OverlappingInstances #-} class Arity f where arity :: f -> Int instance Arity x where arity _ = 0 instance Arity f => Arity ((->) a f) where arity f = 1 + arity (f undefined) Upd Found problem. You need to specify non-polymorphic type for polymorphic functions: arity (foldr :: (a -> Int -> Int) -> Int -> [a] -> Int) Don't know how to solve this yet.

How can I list the methods in a Python 2.5 module?

余生颓废 提交于 2019-12-02 22:03:44
I'm trying to use a Python library written in C that has no documentation of any kind. I want to use introspection to at least see what methods and classes are in the modules. Does somebody have a function or library I can use to list the functions (with argument lists) and classes (with methods and member variables) within a module? I found this article about Python introspection, but I'm pretty sure it doesn't apply to Python 2.5. Thanks for the help. Here are some things you can do at least: import module print dir(module) # Find functions of interest. # For each function of interest: help

How do I inspect the methods of a Ruby object?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-02 20:32:24
I am wondering if there is a Ruby method call that shows only the methods defined by the Ruby object it's called from, as opposed to all the methods defined by its ancestor classes, which is what methods seems to do. methods takes an optional boolean parameter, which specifies whether to also list the methods from the object's class and its superclasses or just the object's singleton methods. So you can do obj.methods(false) to only get the singleton methods defined on obj . If you want the methods defined by the object's class, but not those defined by its superclasses, you can get that by

How do I introspect things in Ruby?

我与影子孤独终老i 提交于 2019-12-02 18:09:33
For instance, in Python, I can do things like this if I want to get all attributes on an object: >>> import sys >>> dir(sys) ['__displayhook__', '__doc__', '__excepthook__', '__name__', '__package__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_getframe', 'api_version', 'argv', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_clear', 'exc_info', 'exc_type', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'getcheckinterval', 'getdefaultencoding',