Reputation: 613
I'm trying to call a class from another file in enthought canopy. I have tried the following:
import sys
import os
a = sys.path.append(os.path.abspath("C:\Users\cost9\OneDrive\Documents\PYTHON\1111\Get_goog_data.py"))
from a import *
ImportError: No module named a
I've also tried:
import os
a = os.system("pC:\Users\cost9\OneDrive\Documents\PYTHON\1111\Get_goog_data.py")
from a import *
Same error. Can anyone help here?
Upvotes: 0
Views: 960
Reputation: 338
what is returned from sys.path.append is not the module you added. Instead, you need to add the path to the module you want to import to sys.path. Then, you can import the module by its name:
import sys
import os
sys.path.append(os.path.abspath(r"C:\Users\cost9\OneDrive\Documents\PYTHON\1111"))
from Get_goog_data import *
Also, as cricket_007 has pointed out, you need to either escape backslashes in the path, or declare it as a raw-string (by prefixing the it with r).
Upvotes: 3