Reputation: 926
Error Output:
This is the current output of my code
money': 2200
Expected Output:
money: 2200
Current Code:
@client.command()
async def stats(ctx):
member = ctx.author
# try:
# with connection.cursor() as cursor:
# # Read a single record
# sql = "SELECT xp_points FROM players WHERE userid = %s"
# values = member.id
# cursor.execute(sql, values)
# result = cursor.fetchone()
# except Exception as e:
# print(f"An error Occurred> {e}")
try:
with connection.cursor() as cursor:
monsql = "SELECT money FROM players WHERE userid = %s"
value = member.id
cursor.execute(monsql, value)
monresult = str(cursor.fetchone())
stripped = str(monresult).strip("{'}")
print(stripped)
except Exception as e:
print(f"An error Occurred> {e}")
# e = discord.Embed(title="Stats Command", color=member.color)
# e.add_field(name="Experience Points", value=result)
# e.add_field(name="💰Coins Gained", value=monresult)
# await ctx.send(embed=e, content=None)
WHy is my code only stripping/removing one quotation mark of the string? Shouldn't it be stripping all the quotation marks it finds? Hope someone can help me with this.
Upvotes: 0
Views: 334
Reputation: 1208
stripped = str(monresult).replace("'", "")
The strip method causes problems as you don’t really know what will be stripped sometimes, so in newer versions of python there will be removeprefix
and removesuffix
. using replace()
will be easier, and you can even specify the number of occurrences that should be replaced.
Upvotes: 0