New to Python I'm trying to setup a simple OOP-structure of files, folders and classes. Here are the file paths:
- C:\Users\Mc_Topaz\Programmering\Python\Terminal\Main.py
- C:\Users\Mc_Topaz\Programmering\Python\Terminal\Connections\Connection.py
- C:\Users\Mc_Topaz\Programmering\Python\Terminal\Connections\NoConnection.py
Notice Connection.py and NoConnection.py is loacted in sub folder Connections.
Connection.py
class Connection:
def __init__(self):
pass
def ToString(self):
pass
NoConnection.py
from Connection import Connection
class NoConnection(Connection):
def __init__(self):
pass
def ToString(self):
print("No connection")
In the Main.py file I would like to call the ToString() method from each class.
Main.py
from Connections.Connection import Connection
from Connections.NoConnection import NoConnection
connection = Connection()
print(connection.ToString())
noConnection = NoConnection()
print(noConnection.ToString())
When I run the Main.py file I get this error:
C:\Users\Mc_Topaz\Programmering\Python\Terminal>Main.py Traceback (most recent call last): File "C:\Users\Mc_Topaz\Programmering\Python\Terminal\Main.py", line 2, in from Connections.NoConnection import NoConnection
File "C:\Users\Mc_Topaz\Programmering\Python\Terminal\Connections\NoConnection.py", line 1, in from Connection import Connection
ImportError: No module named 'Connection'
It seems that the interpreter cannot import the NoConnection class in my Main.py file due to it cannot import the Connection class from the NoConnection.py file. I can run Connection.py and NoConnection.py separately with no problems.
I don't understand why the Main.py don't run. I assume is something super simple and I cannot see it due to I'm to green to Python.