- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Decorators / of Decorator Real-Time Example 1
import MySQLdb try: conn = MySQLdb.connect(user="root", password="sairam143sairam", port=3306, host="localhost") homeCursor = conn.cursor() except Exception as e: print(e) else: print("Database Connected.") #Create a decorator for checking user credentials. def outerFunction(originalFunction): def innerFunction(): userName = input("please enter username") password = input("Please enter password") homeCursor.execute(f"SELECT gmail FROM credentials.users where username='{userName}' and password='{password}';") mail = homeCursor.fetchone() if mail is not None: return originalFunction() else: return "you have no access to get the movie details" return innerFunction @outerFunction def getMyData(): homeCursor.execute(f"SELECT * FROM bulkratings_info.tutorialstution_movies_list;") movieData = homeCursor.fetchall() return movieData movieData = getMyData() if type(movieData).__name__ == 'tuple': for movie in movieData: print(movie) else: print(movieData)