i dont know how i can call function from the file who import.
toolkit.py:
from utilities import bcolors, utility
from backups import backups
import os
version = "1.0"
utility.UpdateNeeded()
class main():
def main():
print( bcolors.BOLD "Toolkit" bcolors.ENDC)
print("")
choose = int(input(bcolors.BOLD "1" ": " bcolors.CYELLOW "Backups" bcolors.ENDC "\n\
" bcolors.BOLD "0" ": " bcolors.CYELLOW "Close" bcolors.ENDC "\n\
> "))
if choose == 0:
#exit
print(bcolors.CGREEN "Ciao." bcolors.ENDC)
exit()
if choose == 1:
#do magic
os.system('cls')
main.menu_backup()
def menu_backup():
choose = int(input(bcolors.BOLD "1" ": " bcolors.CYELLOW "Check Backups" bcolors.ENDC "\n\
" bcolors.BOLD "0" ": " bcolors.CYELLOW "Main Menu" bcolors.ENDC "\n\
> "))
if choose == 0:
os.system('cls')
main.main()
if choose == 1:
os.system('cls')
backups.check_backups()
main.main()
backups.py:
from utilities import bcolors, utility
from toolkit import main
class backups:
def __init__(self, my_dirs, my_files,
curdir):
self.my_dirs = []
self.my_files = []
self.curdir = ''
def check_backups(ln):
print(bcolors.CRED "Check Backups..." bcolors.ENDC)
main.menu_backup()
utilities.py:
class bcolors:
ENDC = '\033[0m'
BOLD = '\033[1m'
CRED = '\33[31m'
CGREEN = '\33[32m'
CYELLOW = '\33[33m'
class utility:
#def __init__(self):
def UpdateNeeded():
print("update check...")
that gives me following error:
ImportError: cannot import name 'backups' from partially initialized module 'backups' (most likely due to a circular import)
CodePudding user response:
In toolkit.py
you are trying to import something from backups.py
, but in backups.py
you are trying to import something from toolkit.py
. Python can't import the one without the other so it goes into a loop, detects it and gives you this error. You need to separate the two components so that they are not dependent on each other anymore.