0

I wrote this code:

@client.command()
async def getinfo(ctx, name):
    url = f'https://api.mojang.com/users/profiles/minecraft/{name}'
    response = requests.get(url)
    uuid = response.json()['id']

    url2 = f'https://api.hypixel.net/player?key=885e4c42-24d4-443a-93a8-ff25483cd6cc&uuid={uuid}'
    response2 = requests.get(url2)
    # END POINTS #
    getuser = response2.json()['player']['displayname']
    getpastuser = response2.json()['player']['knownAliases']
    ###########
    await ctx.send(f'Username: {getuser}\nPast Usernames: {getpastuser}')

This outputs

Username: 35days
Past Usernames: ['UsernameIsntUsed', 'hqcc', '35days']

How can I get rid of the brackets and mini-quotes around the Past usernames part? I have no clue how to do it. I have looked around and tried many methods and nothing seems to work.

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
cdnAshton
  • 29
  • 5
  • "I have looked around and tried many methods and nothing seems to work." When you looked around, did you try putting `python print list without brackets` [into a search engine](https://duckduckgo.com/?q=python+print+list+without+brackets)? When I do that, I get several relevant results ([1](https://www.codeleaks.io/print-list-without-brackets-and-quotes-in-python/), [2](https://blog.finxter.com/how-to-print-a-list-without-brackets-in-python/), [3](https://stackoverflow.com/questions/11178061/print-list-without-brackets-in-a-single-row), etc.). Why do these results not answer your question? – Karl Knechtel Oct 03 '21 at 05:00
  • Even [copying and pasting your question title](https://duckduckgo.com/?q=Discord+Python+Remove+Quotes+and+Brackets) works well for me ([1](https://www.reddit.com/r/learnprogramming/comments/axv3kf/python_how_do_i_remove_the_brackets_from_a_list/), [2](https://www.geeksforgeeks.org/python-remove-square-brackets-from-list/), [3](https://www.delftstack.com/howto/python/list-without-brackets-python/)). How exactly did you look around? What methods did you try? How did they not seem to work? – Karl Knechtel Oct 03 '21 at 05:02
  • Please understand for future reference that you are [expected](https://meta.stackoverflow.com/questions/261592/how-much-research-effort-is-expected-of-stack-overflow-users) to show these things explicitly. Simply claiming that you weren't able to find anything just arouses suspicion, and is also unhelpful (it comes across as venting a frustration; and if you need a more specific answer for some reason, it doesn't help us understand why, or how to specify it better). – Karl Knechtel Oct 03 '21 at 05:03
  • You should also read [ask] and https://stackoverflow.com/help/minimal-reproducible-example. The fact that you're trying to make a Discord bot isn't relevant to the *problem you are experiencing*, so you should provide example code that is specific to the problem, and not add irrelevant tags. – Karl Knechtel Oct 03 '21 at 05:05

2 Answers2

0

Follow this example I think you will get clear concept and easily will solve your issue.

apples = ["Fuji", "McIntosh", "Red Delicious", "Gala", "Jonagold"]
separator = ", "
print(separator.join(apples)) 
-1

Use join on the list... in the event that there other types in the list other than string than cast it to string (may not be necessary)

with casting:

getpastuser = response2.json()['player']['knownAliases']
getpastuserstr = ', '.join(str(e) for e in getpastuser)
await ctx.send(f'Username: {getuser}\nPast Usernames: {getpastuserstr}')

without:

getpastuser = response2.json()['player']['knownAliases']
getpastuserstr = ', '.join(getpastuser)
await ctx.send(f'Username: {getuser}\nPast Usernames: {getpastuserstr}')
ptierno
  • 9,534
  • 2
  • 23
  • 35