0

我正在尝试编写类似于以下内容的内容:

@classmethod
def write(cls, records, values, *args):
    return super(Hello, cls).write(records, values, *args)

但是我在传递 *args 时遇到了问题。我尝试使用 apply (但无法传递记录和值)。我也尝试将 apply 与 partial 一起使用,但没有成功。

当前在 hylang 中不起作用的代码:

(with-decorator classmethod
    (defn write [cls records values &rest args]
      (.write (super Hello cls) records values args)
      ))

在clojure中,我通常会写:

(apply .write (super Hello cls) records values args)

但它似乎适用于 hy 不支持 *args 之前的参数。

如何在 hy 中编写原始 python 代码?

4

1 回答 1

0

我更新到最新版本的 hy

pip install git+https://github.com/hylang/hy.git

在这个最新版本中,apply 已替换为 #*

apply已被 Python 风格的解包操作符#*#**(例如,(f #* args #** kwargs))替换

在新版本的 hy 中,代码可以写成:

(with-decorator classmethod
(defn write [cls records values &rest args]
  (.write (super Hello cls) records values #* args)
  ))
于 2018-01-17T18:50:32.183 回答