作者UBL (funny!)
看板Python
标题[问题] colab 下载档案
时间Thu Jun 9 13:17:34 2022
目前遇到colab 使用files.download下载档案
预期下载3个, 实际下载很多个问题
在def里print string, 也是只出现3行
files.download後加delay也一样
目前还看不出哪来有问题,
再麻烦大家帮忙解惑
谢谢
注:
out_kind.value=='全部' 才有问题
其他选项都正常
sample code:
def gen_sign_file(gen_type):
filename = list(uploaded.keys())[0]
sign_filename = gen_type+'课程研习签到名册'
# 预设可读写,若有需要可以指定write_only和read_only为True
wb = load_workbook(filename=filename, read_only=True)
# 获得所有sheet的名称
print(wb.sheetnames)
doc = Document()
wb.close()
doc.save(sign_filename+'.docx')
files.download(sign_filename+'.docx')
def on_button_clicked(b):
with output:
output.clear_output()
if out_kind.value=='全部':
print("产生 全部 课程研习签到名册")
gen_sign_file('讲师')
gen_sign_file('助教')
gen_sign_file('学员')
elif out_kind.value=='讲师':
print("产生 讲师 课程研习签到名册")
gen_sign_file(out_kind.value)
elif out_kind.value=='助教':
print("产生 助教 课程研习签到名册")
gen_sign_file(out_kind.value)
elif out_kind.value=='学员':
print("产生 学员 课程研习签到名册")
gen_sign_file(out_kind.value)
out_kind = widgets.Dropdown(
options= ['全部','讲师','助教','学员'],
value='全部',
description='输出:',
disabled=False,
)
button = widgets.Button(description="Click Me!")
button.on_click(on_button_clicked)
output = widgets.Output()
display(out_kind)
display(button, output)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.255.12.45 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1654751857.A.33E.html
1F:推 lycantrope: 可以先把function跟widget button拆开来测试 06/10 10:07
2F:→ lycantrope: 单从现有的code看不出来问题出在哪一步 06/10 10:07
3F:→ UBL: 如果不使用button,直接3个gen_sign_file()也是没问题的 06/11 00:06
4F:→ UBL: 目前怀疑是files.download有问题, 因为print()也是印3次 06/11 00:09