How to import a .py file from a directory

I am trying to import a .py file into my jupyter notebook. using the following code , but it is throwing an error. I have also included init.py file in the directory

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

output
No module named ‘test_standard.py’; ‘test_standard’ is not a package

Did you try the following?

import test_standard

Yes , it worked . Thanks

1 Like