Guest User

Untitled

a guest
May 29th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 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 user from %s"%(tablename))
  6.     usernames = list(map(lambda x: x[0], cur.fetchall()))
  7.     db.close()
  8.     return json.dumps(usernames,ensure_ascii=False,indent=2,sort_keys=True)
  9.   except MySQLdb.Error as error:
  10.     print('ERROR in getUsernames\n', error)
  11.     return None
Add Comment
Please, Sign In to add comment