Massimo Scola
asked on
Error when importing Python module: ValueError: Attempted relative import in non-package
I am learning Python and I need some help with this:
I understand that that in order to import, I write from x import y. In my example, I am trying to import quick_sorted from sort.
Both files are in the same folder.
The quick_sort method relies on code which is in the priority queue file.
Interestingly, it is imported this way:
Is there anything wrong with my implementation or with the files supplied?
I import it the following way:
I am trying to use the quick sort method so that I can sort one of my lists.
This is the error I get:
Traceback (most recent call last):
File "C:\Users\massi\Documents\ OU\TMA02_Q 2.py", line 5, in <module>
import sort
File "C:\Users\massi\Documents\ OU\sort.py ", line 11, in <module>
from .priority_queue import PriorityQueue
ValueError: Attempted relative import in non-package
TMA02_Q2.py
sort.py
priority_queue.py
I understand that that in order to import, I write from x import y. In my example, I am trying to import quick_sorted from sort.
Both files are in the same folder.
The quick_sort method relies on code which is in the priority queue file.
Interestingly, it is imported this way:
from .priority_queue import PriorityQueue
The files to import are supplied for me to use.Is there anything wrong with my implementation or with the files supplied?
I import it the following way:
from sort import quick_sorted
I am trying to use the quick sort method so that I can sort one of my lists.
This is the error I get:
Traceback (most recent call last):
File "C:\Users\massi\Documents\
import sort
File "C:\Users\massi\Documents\
from .priority_queue import PriorityQueue
ValueError: Attempted relative import in non-package
TMA02_Q2.py
sort.py
priority_queue.py
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot