如何创建导入最常用的python模块的快捷方式? [英] How do I create a shortcut to import most used python modules?

查看:89
本文介绍了如何创建导入最常用的python模块的快捷方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种自动(或作为快捷方式)在jupyter笔记本中导入一组python模块的方法,这样我就不必在每次创建新笔记本时都将其导入

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

我发现将这些模块导入每个笔记本非常重复.我在这里可能想到的最接近的事情是创建一个python文件并将其作为模块导入,但是我正在Jupyter-notebook中寻找更灵活的东西

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

# 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.

推荐答案

您可能有一个文件frequently_imported_modules.py,其中实际上只有您经常使用的导入,然后将所有这些导入到新脚本中,如下所示:

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:

from frequently_imported_modules import *

这是否是一个好习惯?我不这么认为.

Whether this is a good practice? I don't think so.

这篇关于如何创建导入最常用的python模块的快捷方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆