Advertisement
Guest User

Untitled

a guest
May 29th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.44 KB | None | 0 0
  1. def getUsernames(tablename):
  2.   try:
  3.     db = MySQLdb.connect(host="localhost", user="root", password="root", database="contacts", port=5432)
  4.     cur = db.cursor()
  5.     cur.execute("select name from %s"%(tablename))
  6.     usernames = list(map(lambda x: x[0], cur.fetchall()))
  7.     return json.dumps(usernames,ensure_ascii=False,indent=2,sort_keys=True)
  8.   except MySQLdb.Error as error:
  9.     print('ERROR in getUsernames\n', error)
  10.     return None
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement