2016-06-26 48 views
0

在Clojure repl中,當忘記確切的函數名稱時,我可以使用find-doc來列出其文檔或名稱包含我正在查找的名稱的所有函數。例如:IPython等價於Clojure find-doc?

user=> (xor 1 2) 
CompilerException java.lang.RuntimeException: Unable to resolve symbol: xor in this context, compiling:(/tmp/form-init4743234309821191777.clj:1:1) 

user=> (find-doc "xor") 
------------------------- 
clojure.core/bit-xor 
([x y] [x y & more]) 
    Bitwise exclusive or 
nil 

user=> (bit-xor 1 2) 
3 

如何做的IPython REPL是一回事嗎?

或者什麼是pythonic方式來搜索repl函數? 謝謝。

回答

0

谷歌「巨蟒XOR」給我(多種選擇向下)的官方參考頁

https://docs.python.org/2/reference/expressions.html

頁面發現該帶我到

5.8. Binary bitwise operations 
... 
xor_expr ::= and_expr | xor_expr "^" and_expr 
... 
The^operator yields the bitwise XOR (exclusive OR) of its arguments, which must be plain or long integers. The arguments are converted to a common type. 

該頁面有一個搜索框。如果輸入xor,我可以獲得16頁的鏈接。

我看到例如operator.xor

這如果我這樣做,在IPython中

import operator 
operator.xor? 

In [193]: operator.xor?? 
Type:  builtin_function_or_method 
String form: <built-in function xor> 
Docstring: xor(a, b) -- Same as a^b. 

​​也將顯示operator.xor

x<tab> in Ipython並沒有幫助,因爲沒有內建函數xor...。由於這是作爲一個操作符來實現的,所以搜索將不同於某種功能。

我使用tab完成很多,???查看函數及其代碼(如果在Python中)的文檔。據我所知Ipython沒有鏈接到一般Python文件。

由於我與numpy工作了很多,我還可以搜索'numpy xor',並獲得numpy文檔的鏈接bitwise_xorlogical_xor

np.bit<tab> 

使我

np.bitwise_xor? 
<docs for ufunc using the^operator> 

np.logical_xor顯示我的elementwise陣列操作。

+0

這意味着沒有與Clojure find-doc相當的嚴格等級。相反,我們使用Google來查找功能,不是嗎? – Chad

+0

我瞥了一眼'find-doc'代碼。它收集「命名空間」中的所有文檔並打印與「正則表達式」匹配的文檔。對此沒有任何模糊之處。 Python有一個'help'函數(我用'ipython ??'代替),它導入'pydoc',它可能有其他可能感興趣的工具。 – hpaulj