![](/img/trans.png)
[英]How to include Hy code into a separate file, and then import that using Hy?
[英]How to call variadic function with some parameters before variadic parameter using hy?
我正在嘗試寫類似於:
@classmethod
def write(cls, records, values, *args):
return super(Hello, cls).write(records, values, *args)
但是我在傳遞* args時遇到問題。 我嘗試使用Apply(但無法傳遞記錄和值)。 我也嘗試使用apply部分成功。
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代碼?
我更新到最新版本的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)
))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.