简体   繁体   English

如何创建导入最常用的python模块的快捷方式?

[英]How do I create a shortcut to import most used python modules?

I am looking for a way to automatically (or as a shortcut) import a set of python modules in a jupyter notebook so that I don't have to import them every time I create a new notebook 我正在寻找一种自动(或作为快捷方式)在jupyter笔记本中导入一组python模块的方法,这样就不必在每次创建新笔记本时都导入它们

I am finding it very repetitive to import these modules to every notebook. 我发现将这些模块导入每个笔记本非常重复。 The closest thing I could think here is creating a python file and importing that as a module, but I am looking for something more flexible in Jupyter-notebook 我在这里可能想到的最接近的事情是创建一个python文件并将其作为模块导入,但是我在Jupyter-notebook中寻找更灵活的东西

# Example Code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression 

What could be an easy way to import these long list of modules? 导入这些长长的模块列表的简便方法是什么? as I am finding myself repeating the whole set of modules in every notebook. 因为我发现自己在每个笔记本中都重复了整套模块。

You could have a file frequently_imported_modules.py where you have literally only the imports you use frequently and then import all these in your new script like so: 您可能有一个文件frequently_imported_modules.py ,其中实际上只有您经常使用的导入,然后将所有这些导入新脚本中,如下所示:

from frequently_imported_modules import *

Whether this is a good practice? 这是否是一个好习惯? I don't think so. 我不这么认为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM