简体   繁体   中英

How to pass named arguments into python function from hy

I am trying to use a python function with named arguments from hy.

I'm using the NLTK library as well.

In python I would do something like this

from nltk.corpus import brown
brown.words(categories='news')

to get a list of words in the 'news' category.

I would like to do the same thing in hy. The only way I have figured out to do that is by finding out what order to pass the arguments in, and set all the ones I don't want to None

(import [nltk.corpus [brown]])
(.words brown None "news")

Is there another way to do this in hy that makes my intentions more clear? Imagine trying doing this with a function that has a lot of optional named arguments.

Found the answer in the docs.

defn documentation

It would be done like this

(.words brown :categories "news")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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