好的,这是我的代码。希望你能帮助我。我正在使用名为 MySQLdb 的 MySQL 库。
def createNick(self, user, nick):
try: # TRY STATEMENT HERE SO THE NICK CAN BE RECREATED
db = m.connect("host", "user", "password", "database")
cur = db.cursor()
cur.execute("CREATE TABLE nick_%s(name TEXT NOT NULL)" % user.lower())
cur.execute('INSERT INTO nick_%s(name) VALUES("%s")' % (user.lower(), nick))
db.commit()
except:
db = m.connect("host", "user", "password", "database")
cur = db.cursor()
cur.execute("DROP TABLE nick_%s" % user.lower())
cur.execute("CREATE TABLE nick_%s(name TEXT NOT NULL)" % user.lower())
cur.execute('INSERT INTO nick_%s(name) VALUES("%s")' % (user.lower(), nick))
db.commit()
def getNick(user):
db = m.connect("host", "user", "password", "database")
cur = db.cursor()
cur.execute("SELECT * FROM nick_%s" % user.lower())
nick = [nick[0] for nick in cur.fetchall()]
try: # TRY STATEMENT HERE JUST INCASE USER DID NOT MAKE ONE
return nick
except:
return user
self.createNick("username","<font color='#FFFF'>nickname</font>")
print self.getNick("username")
output: <font color=#FFF>nickname</font>
我的问题是,每次我调用该函数时,它都不会正确地表达 HTML。我什么都试过了,你能帮忙吗?