Advertisement
Guest User

Untitled

a guest
Jun 26th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. from __future__ import print_function
  3. import mysql, mysql.connector, codecs
  4.  
  5. '''Database Operation'''
  6. def connect():
  7. conn = mysql.connector.connect(user = 'root', password = '', unix_socket = "/tmp/mysql.sock", database = 'noname' )
  8. cursor = conn.cursor()
  9. cursor = conn.cursor(buffered=True)
  10. cursor.execute("""SELECT distinct jungle FROM junglebook""")
  11. conn.commit()
  12. conn.close()
  13. from nltk.tokenize import word_tokenize
  14. file = codecs.open("newfile.txt","wb","UTF-8")
  15. for i in cursor:
  16. ram = word_tokenize(''.join(i)) #Tokenize sentences into words
  17. for j in range(len(ram)):
  18. file.write(ram[j]+'n') # Writing to text file
  19. if __name__ == '__main__':
  20. connect()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement