[英]having trouble while connecting python and mysql 2nd time. ie i am impoting same file in line 10, import in 6th line is not working for 2nd time
#name of this file is pass2 #这个文件的名字是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")
#table in mysql is not opening when code is repeated from 10th line and coming back to 6th line of code.6th line imported file help me to show table in mysql after that i have give an import which inport same file(this file)and repeat the procedure .but import file for connection with mysql(6th line) is not working again.当代码从第 10 行重复并返回到第 6 行代码时,mysql 中的 #table 未打开。第 6 行导入的文件帮助我在 mysql 中显示表,然后我给出了一个导入相同文件(此文件)和重复该过程。但用于连接 mysql(第 6 行)的导入文件不再起作用。 plz help
请帮忙
This is not a direct solution for the problem you're asking about.这不是您所询问问题的直接解决方案。 It looks like you (will) have a hard time structuring your app this way with growing number of choices.
随着越来越多的选择,您(将)似乎很难以这种方式构建您的应用程序。 You should split it into smaller functions, each of them dealing with a tiny piece of functionality, and call the functions as needed.
您应该将其拆分为更小的函数,每个函数处理一小部分功能,并根据需要调用这些函数。 Short example:
简短示例:
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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.