0

I'm working on a discord bot in python and so far I've got it to connect and fetch queries from the database and send it to the discord server. But the output is formatted still, how do I remove the brackets/commas.

Code:

@bot.command()
    async def mtop(ctx, arg1):  
    db = pymysql.connect(host=config.db_host, port=3306, user=config.db_user, passwd=config.db_passwd, db=config.db_name)
    cur = db.cursor()
    cur.execute("SELECT name FROM ck_playertimes WHERE mapname = %s AND runtimepro > -1.0 AND style = 0", (arg1,))
    name = cur.fetchone()
    await ctx.send(name)
    cur.close()
    db.close()

It outputs like this:

('Evan',)

Thank you.

1 Answer 1

1

The brackets and commas indicate that "Evan" is inside of a tuple. So if your tuple will only have one element, then you can do ("Evan",)[0] in order to get the first element. If there are several elements in your tuple, then you will need to iterate through each one using a for loop. Like this:

for element in tup:
    # do something with element
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.