Reputation: 433
I have two .py files (modules). I'm trying to import one into the other:
from place import Place
place
is the name of the .py files and Place
name of the class inside it. I am getting an error:
Import "place" could not be resolved Pylance(reportMissingImports)
I have Python installed correctly and modules are both in the same folder. Answers tried:
file_to_do_import.py:
from place import Place
place.py:
class Place:
def __init__(self, place_name, place_address, num_days, total_cost):
# Instance variables for each book instance!!!!
self.place_name = place_name
self.place_address = place_address
self.num_days = num_days
self.total_cost = total_cost
def __str__(self):
# Instance method to return book information as a string!!!!
return "{} by {}, published in {}".format(self.place_name, self.place_address, self.num_days, self.total_cost)
Upvotes: 1
Views: 578
Reputation: 31
2 options:
1). Add a __init__.py
in your directory to make your directory a module.
2). Use from .place import Place
Upvotes: 1