0

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?

White Shadow
  • 444
  • 2
  • 10
  • 26
Cole Starbuck
  • 603
  • 3
  • 11
  • 21

1 Answers1

3

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