是否可以在colab上运行椰子

时间:2020-09-19 06:02:39

标签: google-colaboratory coconut

椰子看起来像一种很棒的语言。我看到它支持Jupyter,但是我不确定在尝试将其安装到Google的colab时出了什么问题。

运行!pip install coconut时,安装成功。

Collecting coconut
  Downloading https://files.pythonhosted.org/packages/c9/53/bfbcdcb7c161e2da2ad142a29c79ff0a198062f616596f220c8c2479a764/coconut-1.4.3-py2.py3-none-any.whl (112kB)
     |████████████████████████████████| 122kB 4.3MB/s 
Requirement already satisfied: prompt-toolkit>=1; python_version >= "3" in /usr/local/lib/python3.6/dist-packages (from coconut) (1.0.18)
Requirement already satisfied: pygments>=2.3.1; python_version >= "2.7" in /usr/local/lib/python3.6/dist-packages (from coconut) (2.6.1)
Collecting cPyparsing<2.4.5.0.1.2,>=2.4.5.0.1.1; platform_python_implementation == "CPython"
  Downloading https://files.pythonhosted.org/packages/f4/2e/11f7fd3dd699c57d27890971e104b632c7f6c4f96a9e58cd062473b39922/cPyparsing-2.4.5.0.1.1.tar.gz (817kB)
     |████████████████████████████████| 819kB 6.1MB/s 
Requirement already satisfied: wcwidth in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit>=1; python_version >= "3"->coconut) (0.2.5)
Requirement already satisfied: six>=1.9.0 in /usr/local/lib/python3.6/dist-packages (from prompt-toolkit>=1; python_version >= "3"->coconut) (1.15.0)
Building wheels for collected packages: cPyparsing
  Building wheel for cPyparsing (setup.py) ... done
  Created wheel for cPyparsing: filename=cPyparsing-2.4.5.0.1.1-cp36-cp36m-linux_x86_64.whl size=3380984 sha256=fbb9198c4c0ba8cb5852d8329ba315ddb809692312d9bdd0a8e9daef982a1607
  Stored in directory: /root/.cache/pip/wheels/dc/1b/e4/387152e217fd984f07e024f63557ce933742be22333d685d86
Successfully built cPyparsing
Installing collected packages: cPyparsing, coconut
Successfully installed cPyparsing-2.4.5.0.1.1 coconut-1.4.3

但是后来我尝试了第一个椰子“案例研究”。

def factorial(n):
    """Compute n! where n is an integer >= 0."""
    if n `isinstance` int and n >= 0:
        acc = 1
        for x in range(1, n+1):
            acc *= x
        return acc
    else:
        raise TypeError("the argument to factorial must be an integer >= 0")

使用isinstance作为中缀运算符会产生语法错误。

当我将isinstance更改为常规函数并尝试测试用例时,发生了同样的事情:

3 |> factorial |> print

另一个语法错误。

我是否无法正确执行安装步骤,或者Colab不能在Colab上正常工作?

谢谢。

P.S。

!coconut -h

回复适当的帮助信息。

P.P.S

!coconut --jupyter

回复Coconut: Successfully installed Coconut Jupyter kernel.

但是colab仍然像没听说过椰子一样运行

0 个答案:

没有答案