小编kak*_*k11的帖子

jupyter下拉小部件触发器动作

我有一个看似简单的意图,只需在jupyter笔记本中有一个下拉小部件来触发一些简单的动作.它有点工作,但是下面的脚本实际上似乎触发了三次事件,我做错了什么?

import ipywidgets as widgets
from IPython.display import display, clear_output
vardict = ["var1","var2"]
select_variable = widgets.Dropdown(
    options=vardict,
    value=vardict[0],
    description='Select variable:',
    disabled=False,
    button_style=''
)
def get_and_plot(b):
    clear_output
    print(select_variable.value)

display(select_variable)
select_variable.observe(get_and_plot)
Run Code Online (Sandbox Code Playgroud)

当我从下拉列表中选择项目时的输出就像是

var1
var2
var2
Run Code Online (Sandbox Code Playgroud)

每次选择都会变得越来越长

我想要的是每种选择只触发一次动作(打印或其他)的方法,我该如何实现?

jupyter ipywidgets

3
推荐指数
1
解决办法
3097
查看次数

clojure无法通过map to list应用函数

我似乎很难理解我应该如何使用clojure map.我有一个对象列表in-grids,我不想使用方法getCoordinateSystem.我想列表中的对象是一些Java类是很重要的.当我在clojure中直接定义函数然后map工作.

这有效:

(.getCoordinateSystem (first in-grids))

但不是这个

(map .getCoordinateSystem in-grids)

错误是: java.lang.RuntimeException: Unable to resolve symbol: .getCoordinateSystem in this context

我可能错过了一些非常明显的东西,但具体到底是什么?

clojure

1
推荐指数
1
解决办法
69
查看次数

标签 统计

clojure ×1

ipywidgets ×1

jupyter ×1