简体   繁体   English

第二次连接python和mysql时遇到问题。 即我在第 10 行导入相同的文件,在第 6 行导入第二次不起作用

[英]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.

相关问题 如何获取19GB文件的第二行-python? - How to get the 2nd line of a 19GB file - python? 我正在尝试将这两行 Matlab 代码转换为 python。第一行没问题,但如何更改第二行? - I am trying to convert these 2 lines of Matlab code into python. first line is fine but how could I change the 2nd line? 删除第2至第9个文件并循环播放timelapse Python - Delete the 2nd to 9th file and loop for a timelapse Python 如何读取第二行和第三行,然后每五行读取一次:第二,第三,第七,第八,十二,十三等 - How to Read the 2nd and 3rd line then Every Fifth Line After: 2nd, 3rd, 7th, 8th, 12th, 13th, etc 如何将第一个文本文件的每一行与 Python 中第二个文本文件的每一行进行比较? - How do I compare every line of the 1st text file to every line of the 2nd text file in Python? 不使用第二个文件更新文件中的一行 - updating a line in file without using 2nd file 尽管在解析同一文本文件时第一次初始化,但 Forloop 没有第二次初始化 - Forloop not initializing the 2nd time despite initializing the 1st time when parsing the same text file 编码定义必须在Python的第1/2行中吗? - Must the encoding definition be in the 1st/2nd line in Python? Python正则表达式匹配行中的第二个或第三个单词 - Python Regex match 2nd or 3rd word in line webpy无法识别for循环中的python第二行 - webpy does not recognizing 2nd line of python in for loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM