如何为Jupyter笔记本中的每个单元启用计时魔法?

时间:2017-02-15 09:19:07

标签: python ipython-notebook jupyter-notebook

fields = [{"Name"=>"CONTACT.MAILADDRESS.LATITUDE", "dataName"=>"Pt_FieldDouble", "externalDataName"=>"number", "isRequired"=>"false", "isReadOnly"=>"false", "maxLength"=>"10", "DisplayLabel"=>"Latitude", "Description"=>"Latitude", "id"=>"999505900000211"}, {"Name"=>"CONTACT.MAILADDRESS.LONGITUDE", "dataName"=>"Pt_FieldDouble", "externalDataName"=>"number", "isRequired"=>"false", "isReadOnly"=>"false", "maxLength"=>"11", "DisplayLabel"=>"Longitude", "Description"=>"Longitude", "id"=>"999505900000212"}, {"Name"=>"CONTACT.STATUS", "dataName"=>"Pt_FieldString", "externalDataName"=>"string", "isRequired"=>"false", "isReadOnly"=>"false", "maxLength"=>"0", "DisplayLabel"=>"Status", "Description"=>"Active/Inactive", "id"=>"999505900000166"}] tree = fields.each_with_object({}) do |field, tree| field = field.dup names = field.delete("Name").split('.') node = names.inject(tree) do |node, name| node[name] ||= {} end node.merge!(field) end require 'pp' pp tree # {"CONTACT"=> # {"MAILADDRESS"=> # {"LATITUDE"=> # {"dataName"=>"Pt_FieldDouble", # "externalDataName"=>"number", # "isRequired"=>"false", # "isReadOnly"=>"false", # "maxLength"=>"10", # "DisplayLabel"=>"Latitude", # "Description"=>"Latitude", # "id"=>"999505900000211"}, # "LONGITUDE"=> # {"dataName"=>"Pt_FieldDouble", # "externalDataName"=>"number", # "isRequired"=>"false", # "isReadOnly"=>"false", # "maxLength"=>"11", # "DisplayLabel"=>"Longitude", # "Description"=>"Longitude", # "id"=>"999505900000212"}}, # "STATUS"=> # {"dataName"=>"Pt_FieldString", # "externalDataName"=>"string", # "isRequired"=>"false", # "isReadOnly"=>"false", # "maxLength"=>"0", # "DisplayLabel"=>"Status", # "Description"=>"Active/Inactive", # "id"=>"999505900000166"}}} %%time魔法可以在Jupyter或iPython笔记本中启用单个单元格的计时。

是否有相似的功能可以为Jupyter笔记本中的每个单元打开和关闭计时?

This question是相关的,但没有回答在每个单元格中自动启用给定魔法的更普遍的问题。

1 个答案:

答案 0 :(得分:2)

一种hacky方法是通过custom.js文件(通常放在 private BufferedImage toGray(BufferedImage image) { int width = image.getWidth(); int height = image.getHeight(); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Color c = new Color(image.getRGB(j, i)); int red = (int) (c.getRed() * 0.3); int green = (int) (c.getGreen() * 0.59); int blue = (int) (c.getBlue() * 0.11); int sum = red + green + blue; Color newColor = new Color(sum, sum, sum); //Color newColor =Color.red; image.setRGB(j, i, newColor.getRGB()); } } return image; } 中)

如何为工具栏创建按钮的示例位于here,这是我根据此答案得出的结果。它只是在按下启用按钮时将所需的魔法的字符串形式添加到所有单元格,并且禁用按钮使用~/.jupyter/custom/custom.js来转动&#34;转动&#34;它关了。

str.replace