Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello to all,

In advance, thank you for those who take the time to explain to me like I am 5.

I am having so much fun creating this program (not a clue what I am doing), I am simply learning about what you can do with Python in a random way.

With that said, I am calling functions from two different custom modules simultaneously. This is not acceptable in Python, as it causes an Import Error.

Papers.py
-----------------
from main_menu import main_menu2

paper_menu() <-- function in Papers.py
Within paper_menu() > call main_menu2()

paper_menu2() <-- function in Papers.py\


main_menu.py
-----------------
from Papers import paper_menu, paper_menu2

main_menu_0() <-- function in main.menu.py
Within main_menu_() > call paper_menu()

main_menu2()
Within main_menu2() > call paper_menu_2()

What I have tried:

I found a solution on Stack Overflow, however I am really new and need guidance on how to translate what this link shows to how it would help me solve the error.

https://stackoverflow.com/questions/72717979/python-importerror-cannot-import-name-from-partially-initialized-module[^]
Posted
Updated 11-Sep-22 1:15am
Comments
Richard MacCutchan 9-Sep-22 3:37am    
What you have posted above is unclear. Please use the Improve question link above, and add the actual code (surrounded by <pre> tags, so it is readable.

1 solution

main_menu.py
--------------------------------------------------------------------
from Banners import main_menu_banner, ordering_menu_banner
from Paper import paper_menu, paper_menu2

main_menu_banner()

def main_menu_0():
	print_white_on_cyan = lambda x: cprint(x, 'white', 'on_cyan')
	print_cyan = lambda x: cprint(x, 'cyan')
	print_cyan("Below are a list of available items in inventory.")
	print_cyan("Select the item of your choice to begin the ordering process:")
	print_cyan("-------------------------------------------------------------")
	print("")
	print("1. Paper")
	print("2. Pens")
	print("3. Supplies")
	print("")
	selection = input("Enter the number for the item you would like to add:  ")
	print("")
	if (selection == '1'):
		paper_menu()
	print("")

main_menu_0()

def main_menu2():
	print_white_on_cyan = lambda x: cprint(x, 'white', 'on_cyan')
	print_cyan = lambda x: cprint(x, 'cyan')
	print_cyan("Below are a list of available items in inventory.")
	print_cyan("Select the item of your choice to begin the ordering process:")
	print_cyan("-------------------------------------------------------------")
	print("")
	print("1. Paper")
	print("2. Pens")
	print("3. Supplies")
	print("")
	selection = input("Enter the number for the item you would like to add:  ")
	print("")
	if (selection == '1'):
		paper_menu2()
	print("")


Papers.py
---------------------------------------------------------------------
from main_menu import main_menu2

def paper_menu():
	print("We have the following paper types to select from: ")
	print("1. Paper type 1")
	print("2. Paper type 2")
	print("3. Paper type 3")
	paper_selection = input("Enter the selection number for the paper type you would like to order.")
	if (paper_selection == "1"):
		print("You have selected Paper type 1.")
		confirm_paper_selection = input("Is this correct? 'y/n'")
		if (confirm_paper_selection == "y"):
			quantity_paper_type_1 = input("Enter the amount of paper reams you would like to order.")
			print(f"You have entered {quantity_paper_type_1} for {paper_selection}.")
			confirm_quantity_paper_selection = input("Is this correct? 'y/n'")
			if(confirm_quantity_paper_selection == "y" or confirm_quantity_paper_selection == "Y"):
				print(f"You are about to place an order for {paper_selection} for  ")
				print(f"{quantity_paper_type_1}.")
				dept_num = input("Enter the department number to bill the purchase to: ")
				print(f"You entered {dept_num}.")
				confirm_dept_num = input("Is this correct? 'y/n' ? ")
				if (confirm_dept_num == "y" or confirm_dept_num == "Y"):
					auth_code = int(input("Enter your authorisation code to continue:"))
					if (auth_code == 456):
						print("Authorisation code accepted.")
					else:
						print("Invalid authorisation code.")
						auth_code2 = input("Re-enter authorisation")
						if(auth_code2 == 456):
							print("Authorisation code accepted.")
							print("Would you like to complete your purchase or")
							print("would you like to return to the main menu to add")
							return_to_main_menu = input("additional items?")
							if(return_to_main_menu == "y" or "Y"):
								main_menu2()
								
						else:
							print("Invalid authorisation code.")
							print("Program exiting...")
							exit
		
def paper_menu2():
	print("We have the following paper types to select from: ")
	print("1. Paper type 1")
	print("2. Paper type 2")
	print("3. Paper type 3")
	paper_selection = input("Enter the selection number for the paper type you would like to order.")
	if (paper_selection == "1"):
		print("You have selected Paper type 1.")
		confirm_paper_selection = input("Is this correct? 'y/n'")
		if (confirm_paper_selection == "y"):
			quantity_paper_type_1 = input("Enter the amount of paper reams you would like to order.")
			print(f"You have entered {quantity_paper_type_1} for {paper_selection}.")
			confirm_quantity_paper_selection = input("Is this correct? 'y/n'")
			if(confirm_quantity_paper_selection == "y" or confirm_quantity_paper_selection == "Y"):
				print(f"You are about to place an order for {paper_selection} for  ")
				print(f"{quantity_paper_type_1}.")
				dept_num = input("Enter the department number to bill the purchase to: ")
				print(f"You entered {dept_num}.")
				confirm_dept_num = input("Is this correct? 'y/n' ? ")
				if (confirm_dept_num == "y" or confirm_dept_num == "Y"):
					auth_code = int(input("Enter your authorisation code to continue:"))
					if (auth_code == 456):
						print("Authorisation code accepted.")
					else:
						print("Invalid authorisation code.")
						auth_code2 = input("Re-enter authorisation")
						if(auth_code2 == 456):
							print("Authorisation code accepted.")
							print("Would you like to (1.) Complete your purchase or")
							print("would you like to (2.) Return to the main menu to add")
							return_to_main_menu = input("additional items?")
							if(return_to_main_menu == 1):
								print("DEBUG: line 77.")
								
							elif return_to_main_menu == 2 :
								print("DEBUG: line 79.")
							else: 
								exit
								
						else:
							print("Invalid authorisation code.")
							print("Program exiting...")
							exit
		
			#	else:
					# other command
				else:
					print("DEBUG: line 87.")
				# other command
		else:
			print("DEBUG: line 90.")
	else:
		print("DEBUG: line 92.")
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900