Python 仍然不间断地运行。会有帮助的 class Cursor(object): def __init__(self, username, password

Python 仍然不间断地运行。会有帮助的 class Cursor(object): def __init__(self, username, password ,python,mysql,while-loop,Python,Mysql,While Loop,仍然不间断地运行。会有帮助的 class Cursor(object): def __init__(self, username, password ): # init your connection here def __iter__(self): # for reading content of cursor def __enter

仍然不间断地运行。会有帮助的

class Cursor(object):
    def __init__(self,
                 username,
                 password
                 ):
        # init your connection here

    def __iter__(self):
        # for reading content of cursor

    def __enter__(self):
        # something executed before establish connection

    def __exit__(self, ext_type, exc_value, traceback):
        # something executed when there is an error or connection finishes

with Cursor() as cursor:
    print(cursor)
    connection = (cursor.connection)
    print(connection)