JustBlossom
JustBlossom

Reputation: 1329

Python Import Error but in the same directory

This may seem like a easy question, but I have tried my best to figure it out.

I have two files:

Car.py and Dealership.py

They are in the same directory. Dealership.py contains a bunch of methods and another class that I would like to use in Car.py. The class name is "worker".

So in Car.py I write at the top of the file:

from Dealership import worker

I have also tried:

import Dealership

I continually get this error:

 No module named Dealership

I can't understand why. As far as I know, and according to pydocs, I am writing the imports correctly, and the files are in the same directory.

Thanks for any advice

Upvotes: 1

Views: 5662

Answers (1)

Sheng
Sheng

Reputation: 3555

You need to add the current directory to the sys.path, so that the Python will try to find the module here.

import sys
sys.path.append(".")

Upvotes: 1

Related Questions