- Home
- Course Detail
regularpython@gmail.com
You are now watching:
Python Loops / of Python Loops Real-Time Example
import MySQLdb from beautifultable import BeautifulTable table = BeautifulTable() table.column_headers = ["Movie Name", "Movie Language"] table.column_alignments['Movie Name'] = BeautifulTable.ALIGN_LEFT try: connection = MySQLdb.connect(user='root',password='sairam143sairam',port=3306,host='localhost') except Exception as e: print(e) else: tutorialCursor = connection.cursor() tutorialCursor.execute("SELECT movie_name,movie_language FROM bulkratings_info.tutorialstution_movies_list;") Movies = tutorialCursor.fetchall() connection.close() count = 0 for Movie in Movies: try: print(Movie) if Movie[1] == 'Hindi' or Movie[1]=='Telugu': continue count+=1 table.append_row([Movie[0], Movie[1]]) if count ==10: break # else: # count = count + 1 # table.append_row([Movie[0], Movie[1]]) except: pass print(table)