每一次用jupyter的Snippets时,先Shuttdown,再重新进入

Snippets使用及注意事项

    • 代码:
    • 代码说明:
    • 注意事项:

代码:

import json
path = get_ipython().getoutput('jupyter --data-dir')
path = "".join([path[0], r"/nbextensions/snippets/snippets.json"])
snips = {
    "name": "导入库_多因子分析",
    "code": [
        'import pandas as pd ',
            'import numpy as np',
        'import scipy.stats as ss',
        'import matplotlib.pyplot as plt ',
        'import seaborn as sns',
        'ns.set_context(font_scale=1.5)'
    ]
}
fr = open(path, 'r', encoding='UTF-8')
mode = json.load(fr)
fr.close()
for i in range(0, len(mode['snippets'])):
    if mode['snippets'][i]['name'] == '爬虫_requests':
        del mode['snippets'][i]
        break
mode['snippets'].append(snips)
jsObj = json.dumps(mode)
with open(path, "w") as fw:
    fw.write(jsObj)
    fw.close()

代码说明:

每一次用jupyter的Snippets时,先Shuttdown,再重新进入_第1张图片

注意事项:

每一次用jupyter的Snippets时,先Shuttdown,再重新进入

你可能感兴趣的:(Snippets,Juypter)