在将IPython笔记本转换为笔记本时,我试图隐藏一些特定的单元格。我想在课堂上使用笔记本,并希望从包含问题和答案的主笔记本中生成“运动”笔记本。
This post很有帮助,但是由于某些原因,在将笔记本转换为笔记本时使用标签和预处理器的方法不起作用(在转换为PDF和HTML时有效)。
有什么想法吗?预先感谢!
答案 0 :(得分:1)
使用nbformat(已经安装了jupyter)非常简单:
f_response = {
'val0':[1,2,3,[True],[42]],
'val1':{}, # assuming {} ,[] are Falsey values bool({}) False
'val2':['x'],
'val3':[[[False]]]
}
t_response = {
'val0':[1,2,3,[True],[42]],
'val1':{1:[43]},
'val2':['x'],
'val3':[[[True,[True]]]]
}
response = {
"key1": {"foobar" : ["a", None, {"xyz": 123}]},
"key2":"value2",
"key3":"value3",
"key4":[
[4, 5, 6],
[]
],
"key5":"value4",
"key6":"value5",
"key7":{
"key1":"value1",
"key2":"value2",
"key3":"value3",
"key4":"value4",
"key5":"value5",
"key6":"value6"
},
"key8":"value6"
}
def check_values(payload):
if isinstance(payload, dict):
if payload != {}:
for value in payload.values():
if isinstance(value, list):
if not check_values(value):
return False
elif isinstance(value, dict):
if not check_values(value):
return False
else:
if not bool(value):
return False
else:
return False
elif isinstance(payload, list):
if payload != []:
for value in payload:
if isinstance(value, list):
if not check_values(value):
return False
elif isinstance(value, dict):
if not check_values(value):
return False
else:
if not bool(value):
return False
else:
return False
return True
print(check_values(f_response)) #False
print(check_values(t_response)) #True
print(check_values(response)) #False