小编Dea*_*ean的帖子

使用 ipywidgets FileUpload 小部件时,我可以定义文件上传操作吗

我想在上传文件时创建一个事件,widgets.FileUpload就像我widgets.Button使用.on_click(some_function). 有没有办法做这样的事情

import ipywidgets as widgets

def do_something_with_file(fu):

    content = fu.data[0].decode('utf-8') 
    # doing something with the file content and get some string output
    return 'some string'

str_file_upload = widgets.FileUpload(accept='.txt', multiple=False)
str_file_upload.on_upload(do_something_with_file)

Run Code Online (Sandbox Code Playgroud)

python widget ipython jupyter jupyter-notebook

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

标签 统计

ipython ×1

jupyter ×1

jupyter-notebook ×1

python ×1

widget ×1