简体   繁体   English

Scala相当于Python的帮助()

[英]Scala equivalent of Python help()

I'm proficient in Python but a noob at Scala. 我精通Python,但在Scala是一个菜鸟。 I'm about to write some dirty experiment code in Scala, and came across the thought that it would be really handy if Scala had a function like help() in Python. 我即将在Scala中编写一些脏的实验代码,并且认为如果Scala在Python中有像help()这样的函数,它会非常方便。 For example, if I wanted to see the built-in methods for a Scala Array I might want to type something like help(Array) , just like I would type help(list) in Python. 例如,如果我想看到Scala Array的内置方法,我可能想要输入类似help(Array) ,就像我在Python中输入help(list) Does such a thing exist for Scala? Scala有这样的事吗?

I do not know of one built-in but you should use Scaladocs to find the same information. 我不知道有一个内置但你应该使用Scaladocs来查找相同的信息。

Unless you use eclipse which has an auto complete with short explanations. 除非你使用具有自动完成和简短解释的eclipse。 For instance it will give you all the commands for arrays after typing 'array.'. 例如,在输入“array”后,它将为您提供阵列的所有命令。

I think tab completion is the closest thing to Python's help. 我认为tab完成是最接近Python帮助的东西。

There is also a dated but still relevant post from @dcsobral on using Scala documentation and Scalex which is similar to Hoogle for Haskell. @dcsobral还有一篇关于使用Scala文档和Scalex的日期但仍然相关的帖子 ,类似于Hoogle for Haskell。

This is the tab completion in the Object Array . 这是Object Array的选项卡完成。

scala> Array.
apply                  asInstanceOf           canBuildFrom           concat                 copy                   
empty                  emptyBooleanArray      emptyByteArray         emptyCharArray         emptyDoubleArray       
emptyFloatArray        emptyIntArray          emptyLongArray         emptyObjectArray       emptyShortArray        
fallbackCanBuildFrom   fill                   isInstanceOf           iterate                newBuilder             
ofDim                  range                  tabulate               toString               unapplySeq   

This is for the methods on the class Array . 这是针对类Array的方法。 Not sure why this doesn't show value members after a. 不知道为什么这不会显示价值成员后a.

scala> val a = Array(1,2,3)
a: Array[Int] = Array(1, 2, 3)

scala> a.
apply          asInstanceOf   clone          isInstanceOf   length         toString       update  

Though a little daunting at times tab completion on a method shows the method signatures. 虽然有时候方法上的选项卡完成有点令人生畏,但会显示方法签名。 Here it is for Array.fill 这是Array.fill

def fill[T](n1: Int, n2: Int)(elem: => T)(implicit evidence$10: reflect.ClassTag[T]): Array[Array[T]]                                                   
def fill[T](n1: Int, n2: Int, n3: Int)(elem: => T)(implicit evidence$11: reflect.ClassTag[T]): Array[Array[Array[T]]]                                   
def fill[T](n1: Int, n2: Int, n3: Int, n4: Int)(elem: => T)(implicit evidence$12: reflect.ClassTag[T]): Array[Array[Array[Array[T]]]]                   
def fill[T](n1: Int, n2: Int, n3: Int, n4: Int, n5: Int)(elem: => T)(implicit evidence$13: reflect.ClassTag[T]): Array[Array[Array[Array[Array[T]]]]]   
def fill[T](n: Int)(elem: => T)(implicit evidence$9: reflect.ClassTag[T]): Array[T]  

同样,IDEA有“快速文档查找”命令,该命令适用于Scala以及Java(-Doc)JAR和源代码文档注释。

sbt-man is a sbt plugin for looking up scaladoc. sbt-man是一个用于查找scaladoc的sbt插件。 The sbt console command starts the Scala REPL with project classes and dependencies on the classpath sbt console命令启动Scala REPL,其中包含类路径上的项目类和依赖项

Example: 例:

man Traversable /:
[man] scala.collection.Traversable
[man] def /:[B](z: B)(op: (B ⇒ A ⇒ B)): B
[man] Applies a binary operator to a start value and all elements of this
collection, going left to right. Note: /: is alternate syntax for foldLeft;
z /: xs is the same as xs foldLeft z. Note: will not terminate for infinite-
sized collections. Note: might return different results for different runs,
unless the underlying collection type is ordered. or the operator is
associative and commutative. 

In scala , you can try using the below ..( similar to the one we have in python ).. 在scala中,你可以尝试使用下面的..(类似于我们在python中的那个)..

help(RDD1) in python will give you the rdd1 description with full details. python中的help(RDD1)将为您提供rdd1描述以及完整的详细信息。

Scala > RDD1.[tab] Scala> RDD1。[tab]

On hitting tab you will find the list of options available to the specified RDD1, similar option you find in eclipse . 在点击选项卡上,您将找到指定RDD1可用的选项列表,您可以在eclipse中找到类似选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM