Newbie here
I want to import a class from a file in another directory, in this case:
C:\Users\jose_\Desktop\my_ref\stack_class.py
, using the from
- import
statement. I have an init.py file in said directory but cannot find the right sintax anywhere.
How do you put C:\Users\jose_\Desktop\my_ref\stack_class.py
in the import part?
I have tried using these other two ways:
exec(open("file path on windows").read())
and the import sys and sys.path.insert
they both work, trying to do it with the import statement.
from C:\Users\jose_\Desktop\my_ref\stack_class.py import Stack #Error here
foo = Stack()
print(type(foo))
Error
File "C:/Users/jose_/OneDrive/Mis_Documentos/Educacion/Linkedin/Ex_Files_Python_Data_Structures_Queues/Exercise_Files/Ch02/02_02/End/main2.py", line 4
from C:\Users\jose_\Desktop\my_ref\stack_class.py import Stack
^
SyntaxError: invalid syntax