# coding: utf-8
# # 导入相关模型,设置相关变量
# In[1]:
path = get_ipython().getoutput('jupyter --data-dir')
path = "".join([path[0],r"/nbextensions/snippets/snippets.json"])
import json
# # 查看已安装的snips
# In[2]:
file = open(path,"r",encoding="utf-8")
snips = json.load(file)
print("原来的snips:")
print(snips)
# # 设置自定义snips,<————**自定义snippet代码段写在这里**
# In[4]:
snips = {
"snippets" : [
{
"name" : "初始化jupyter",
"code" : [
'# Jupyter 默认设置',
'%matplotlib inline',
'%config InlineBackend.figure_format="retina"',
'%config InlineBackend.rc = {"figure.figsize": (7.5,4.5)}'
]
},
{
"name" : "导入常见模块",
"code":[
'import numpy as np'
'\n'
'import torch'
]
},
{
"name" : "重新加载模块",
"code" : [
"# 重新加载所有模块",
"%load_ext autoreload",
"%autoreload 2"
]
},
]
}
原来的snips:
{'snippets': [{'name': '初始化jupyter', 'code': ['# Jupyter 默认设置', '%matplotlib inline', '%config InlineBackend.figure_format="retina"', '%config InlineBackend.rc = {"figure.figsize": (7.5,4.5)}']}, {'name': '导入常见模块', 'code': ['import numpy as np\nimport torch']}, {'name': '重新加载模块', 'code': ['# 重新加载所有模块', '%load_ext autoreload', '%autoreload 2']}]}
# # 写入snips
# In[5]:
model = snips #数据
with open(path,'w',encoding='utf-8') as json_file:
json.dump(model,json_file,ensure_ascii=False)
x1.00
把要保存的代码写在这里:
?效果:
?
|