I want to import a file in a local directory but python refused to do so and it gives error everytime i do so.
I tried putting "from Admin_login import Admin_login" but it gives an error saying
"ModuleNotFoundError: No module named 'Admin_login'"
my code:-(main.py)
from .Admin_login import Admin_login
loggsin = Admin_login.login()
if loggsin == True:
print("You are logged in")
This is the Admin_login.py file
import json
import os
def load_data():
with open("data.json", "r") as f:
Data = json.load(f)
return Data
class Admin_login():
def login(self):
Login = False
while Login == False:
id = input("Enter the id you want to login = ")
data = load_data()
if id == data["id"]:
print(data["name"])
passord = input("Enter the password = ")
if passord == data["password"]:
print("You are successfully logged in")
Login = True
return Login
os.system('cls')
else:
print("The id doesn't exist... Please try again!")
Login = False
return Login
os.system('cls')
if __name__ == '__main__' :
Admin_login()
and the error it gives is :-
Traceback (most recent call last):
File "C:\Users\myUser\Desktop\LibApp\main.py", line 1, in <module>
from .Admin_login import Admin_login
ImportError: attempted relative import with no known parent package
pls help
.and it should workmain.pybecause that function doesn't exist. You will need to callAdmin_login.Admin_login()in your first line of non-import code.