Advertisement
Guest User

Untitled

a guest
Apr 7th, 2017
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Sun Feb 26 10:15:53 2017
  4.  
  5. @author: 116749
  6. """
  7. import sys
  8. import pymysql.cursors
  9. # Connect to the database
  10. connection = pymysql.connect(host='localhost', user='root', password='installer', db='pytamil', charset='utf8mb4', cursorclass=pymysql.cursors.DictCursor)
  11. try:
  12. with connection.cursor() as cursor:
  13. # Create a new record
  14. # sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
  15. # cursor.execute(sql, ('webmaster@python.org', 'very-secret'))
  16. # connection is not autocommit by default. So you must commit to save
  17. # your changes.
  18. # connection.commit()
  19. with connection.cursor() as cursor:
  20. # Read a single record
  21. sql = "SELECT * from tamil"
  22. # WHERE `email`=%s"
  23. # cursor.execute(sql, ('webmaster@python.org',))
  24. cursor.execute(sql)
  25. result = cursor.fetchall()
  26. #print (str(result).encode('utf-8'))
  27. #print (str(result).encode('raw-unicode-escape').decode('utf-8'))
  28. print (result[0][u'data'])
  29.  
  30. f = open('output.txt', 'w')
  31. f.write(result[0][u'data'].encode('utf8'))
  32. f.close()
  33.  
  34. # mystring = [u'\u0bb5', u'\u0ba3' u'\u0b95' u'\u0bcd' u'\u0b95' u'\u0bae' u'\u0bcd']
  35. finally:
  36. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement