当使用Jupyter笔记本时,执行单元格的输出(包括错误消息)可能很有用,因此我希望单独使用其输出冻结单元格,或者换句话说, 取消激活单元格以保持输出。
这可行吗?
答案 0 :(得分:2)
从历史上看,这样的功能有not been available in native Jupyter。
但是,您可以尝试Jupyter extension called "Runtools"可用,它会显示一个应该运行所有单元格并忽略异常的按钮。
答案 1 :(得分:1)
另一种不需要任何第三方工具的替代方法是编辑笔记本的元数据,如here所述。
要编辑单元格的元数据,您有两个选择。对我有用的是在编辑器中打开笔记本,然后寻找我想锁定的单元格。但是,这不是一个非常有效的过程。建议在此answer中使用更简单的方法:
View
。Cell Toolbar
,然后选择Edit Metadata
。Edit Metadata
按钮将出现在单元格的右上角。但是,因为我正在与Jupyter Lab合作,所以这些菜单和选项没有出现在这里,所以我无法使用它。
一旦您到达json文件(或部分)中单元的元数据,只需添加以下几行:
"metadata": {
"trusted": true,
"editable": false,
"deletable": false
}
在Jupyter中保存并重新加载笔记本电脑,tadah !,您的单元格不能被修改或删除。
不幸的是,仍然可以通过在菜单栏中有选择地选择该选项来清除输出(Edit
> Clear Ouputs
)。当然,只有在您要清除输出而不仅仅是运行单元格来更新输出时,才会发生这种情况。
答案 2 :(得分:0)
默认nbextensions套件中现在有一个名为import RPi.GPIO as GPIO
import MFRC522_Chip2
import MFRC522
import signal
plate1 = [222, 86, 127, 87, 246]
plate2 = [86, 126, 214, 255, 87]
indicator1 = 0
indicator2 = 0
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
continue_reading = True
# Capture SIGINT for cleanup when the script is aborted
def end_read(signal,frame):
global continue_reading
print "Ctrl+C captured, ending read."
continue_reading = False
GPIO.cleanup()
# Hook the SIGINT
signal.signal(signal.SIGINT, end_read)
# Create an object of the class MFRC522
MIFAREReader_Chip2 = MFRC522_Chip2.MFRC522()
# Create an object of the class MFRC522
MIFAREReader = MFRC522.MFRC522()
# Welcome message
print "Welcome to the MFRC522 data read example"
print "Press Ctrl-C to stop."
# This loop keeps checking for chips. If one is near it will get the UID and authenticate
while continue_reading:
# Scan for chip 1
(status,TagType) = MIFAREReader.MFRC522_Request(MIFAREReader.PICC_REQIDL)
#print (status)
# If a card is found
if status == MIFAREReader.MI_OK:
print ("Card 1 detected")
# Get the UID of the card
(status,uid) = MIFAREReader.MFRC522_Anticoll()
if indicator1 == 1:
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.LOW)
print ("!")
else:
GPIO.setup(12, GPIO.OUT)
GPIO.output(12, GPIO.HIGH)
indicator1 = 0
print (uid)
# If we have the UID, continue
if status == MIFAREReader.MI_OK:
if uid[:5] == plate1:
print ("Plate 1 in position")
indicator1 = 1
else:
("Find plate 1")
indiator1 = 0
# Scan for chip 2
(status,TagType) = MIFAREReader_Chip2.MFRC522_Request(MIFAREReader_Chip2.PICC_REQIDL)
#print (status)
# If a card is found
if status == MIFAREReader_Chip2.MI_OK:
print ("Card 2 detected")
# Get the UID of the card
(status,uid) = MIFAREReader_Chip2.MFRC522_Anticoll()
if indicator2 == 1:
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, GPIO.LOW)
print ("?")
else:
GPIO.setup(16, GPIO.OUT)
GPIO.output(16, GPIO.HIGH)
indicator2 = 0
print (uid)
#If we have the UID, continue
if status == MIFAREReader_Chip2.MI_OK:
if status == MIFAREReader.MI_ERR:
if uid[:5] == plate2:
print ("Plate 2 in position")
indicator2 = 1
else:
print("Find plate 2")
indiator2 = 0
的扩展名。
Freeze
并从任何笔记本中打开pip install jupyter_contrib_nbextensions
以启用冻结功能。