第二次连接python和mysql时遇到问题.我在第10行导入同一个文件,第6行导入第2次不起作用



#此文件的名称为pass2

print("welcome home")
main=input("enter 1 for viewing databases,     enter 2 for editing databases,     3 for paying fees/n")
if main=="1":
com=input("enter s for students,     enter t for teachers")
if com=="s":
import connect
#importing file for connection with mysql which help me to show table of mysl
print("press 1 to go home, press 2 to exit")
#option for starting same work again
x=int(input("enter your choice:"))
if x==1:
import pass2
#pass2 is this same file which help people to restart this code
elif x==2:
exit()
else:
print("this choice is no available")
elif com=="t":
print("hi teacher")
else:
print("invalid entry")
elif main=="2":
com2=input("enter s for  editing students,     enter t for editing teachers")
if com2=="s":
print("edit student")
elif com2=="t":
print("edit teacher")
else:
print("invalid entry")
else:
print("invalid entry")

#当代码从第10行重复到代码的第6行时,mysql中的表没有打开。第6行导入的文件帮助我在mysql中显示表,之后我导入了同一个文件(这个文件(并重复该过程。但用于连接mysql的导入文件(第6行(无法再次工作。plz帮助

这不是您所问问题的直接解决方案。随着越来越多的选择,你(将(很难以这种方式构建你的应用程序。您应该将其拆分为更小的函数,每个函数处理一小段功能,并根据需要调用这些函数。简称:

def entry_point():
"""this is entry point of the whole app"""
main = input("enter 1 for viewing databases,     enter 2 for editing databases,     3 for paying fees/n")
if main == "1":
chosen_db = input("enter s for students,     enter t for teachers")
database_view(chosen_db)
elif main == "2":
chosen_db=input("enter s for  editing students,     enter t for editing teachers")
database_editing(chosen_db)

def database_view(chosen_db):
"""called from entry_point()"""
if chosen_db == "s":
print("press 1 to go home, press 2 to exit")
x=int(input("enter your choice:"))
if x == 1:
do_db_mumbo_jumbo()
elif x==2:
# calling entry_point() instead of exit() will return you to the start of the app
# entry_point()
exit()
else:
print("this choice is no available")
...
entry_point()

最新更新