如何使用目录在 jupyter notebook 上导入 .py 文件

问题描述

我想使用目录在 jupyter notebook 上导入 .py 文件。我如何在 jupyter 上导入这个文件文件路径 - C:\Users\Documents\AFR\hunk.py

例如,我想将 test_standard.py 文件中的所有函数导入到我的 main.py 像这样

import sys 
import os
sys.path.append(os.path.abspath("/Users/hp/Documents/AFR"))
import test_standard.py

但我收到错误 没有名为“test_standard.py”的模块; 'test_standard' 不是一个

@james

解决方法

代替 导入 test_standard.py #不正确 import test_standard #将作为文件名需要导入