How do I import a module into a different file, in the same directory?

117
December 10, 2019, at 02:00 AM

In one of my folders/directories, I have a module named "restaurant_class.py" with a class that I am trying to import into a different module named "restaurant_instance.py"

from restaurant_class import Restaurant

In the same directory I do have a blank file named __init__.py.

Every time I try to import the module and class, it keeps giving me the error

no module named 'restaurant_class'

How do I import a module and/or class from a module that I created?

Answer 1

I figured out my problem. In my File Explorer to locate the directory, I was in the wrong directory. The files are placed correctly, just had the wrong directory pulled up in Spyder.

READ ALSO
Delay in Real-Time Reading from Multiple Serial Ports (GPS, through RS232 - USB adapter)

Delay in Real-Time Reading from Multiple Serial Ports (GPS, through RS232 - USB adapter)

At the moment i am working on a ROS system with multiple sensors through various interfaceTwo of the most important sensors are GPS and Gyro that are connected through RS323 - USB adapter

118
Mocking Elasticsearch API in python

Mocking Elasticsearch API in python

I want to mock Elasticsearch for bulk inserts, where I have packaged bulk insert in a method like below:

172
How to use Popen using Python on Windows?

How to use Popen using Python on Windows?

I am trying out an example Pipe program using Python on Windows

289
Python - logger is not defined error if class using logger is imported rather then in main py file

Python - logger is not defined error if class using logger is imported rather then in main py file

The code below will log from main and from RequestReport class just fine as isIt does not error at all and both main and RequestReport log to my file

151