I am trying to import a file into Python shell. I have read multiple answers on this site to the same question asked by other users, but none of them have worked.
The command I type is:
import filename.py
I have also tried typing:
from filename import *
In IDLE I clicked File -> Path Browser to make sure my file was saved in one of those folders.
Am I doing any steps wrong?
Look here: Importing files in Python?
Credit to Pradyun for his excellent answer:
If you are working in the same directory, that is, b.py is in the same folder as a.py, I am unable to reproduce this problem (and do not know why this problem occurs), but it would be helpful if you post what os.getcwd() returns for b.py.
If that's not the case, add this on top of b.py
import sys
sys.path.append('PATH TO a.py')
OR if they are in the same path,
import sys
sys.path.append(os.basename(sys.argv[0])) # It should be there anyway but still..
Please do further research before posting your answer.