0

Building a webscraper for a game I love and right now came into a little issue with python, what I want to do could best be show as:

userdata = { ' ', [ ]}

I'm new to writing python so my question is would this work given the following scenario: User's account name (which players in the game use to message each other) wants to attach multiple character names to that single account name so other players know that all these characters belong to that one account.

The end result should be something like this:

"Please enter your account name followed by which characters you wish associated with this account:" user input: Leafzer Leaf1 Leaf2 Leaf3

current limitations in the game work to python's advantage as account and character names can not have any white space. I was considering using split such as:

x = [str(x) for x in input("Enter user data: ").split()]

but as it stands neither of these seem to work quite right.

To reiterate and maybe clear some of the confusion: Writing a website scraper that allows players in the game to enter their account name and a list of mules (characters in the game that just hold items). The list of mules and the account name must be separate as my scraper uses the list of mules to go to a certain website using that mule name and downloads the data into a searchable csv file. If another player searches for an item that is within that csv file, it brings up the account name associated with the mule rather than the mule name and displays the account name to player searching for the item.

I'm stuck trying to figure out how to obtain the user data in this manner. Any help would be appreciated.

1 Answer 1

0

Are you after something like this:

users = {}
user, *chars = input("Please input your name and characters: ").split(" ")
users[user] = chars

?

Or slightly less confusingly (but not nearly as neatly):

users = {}
words = input("Please input your name and characters: ").split(" ")
user = words[0]
chars = words[1:]
users[user] = chars

But * unpacking is great, and everyone should use it!

P.S. for your second use case, just call input() twice!:

username = input("Please input your name: ")
chars = input("Please input your characters: ").split(" ")
6
  • I think I understand and this is almost exactly what I'm looking for. My next question to you would be how would I do something where I separated asking for "Account name (user) and Character names (chars)?" I'm thinking users may get confused asking for things in the same line... age old programmer rule never trust the End user. So how would I accomplish exactly what you just put but in 2 different segments so I can ask "What is your Account name?" and "What characters do you want searchable?"
    – Leafzer
    Sep 20, 2021 at 18:57
  • just use two lines! but I'll edit the answer
    – 2e0byo
    Sep 20, 2021 at 18:59
  • You're awesome, thank you! Seeing it put in two lines for some reason helped me understand it a lot more. Still starting out with python but I'm loving it!
    – Leafzer
    Sep 20, 2021 at 19:04
  • @Leafzer oh good :) python is very logical: if you break it up there is always a way to solve it (and it normally makes sense).
    – 2e0byo
    Sep 20, 2021 at 19:09
  • just to be clear, the characters are being saved as a list in the dictionary and thus will behave as a list does to that key:value pairing so if I want to call that specific character, how would I do that? Would it be something as simple as users["username"][x] where x is the element number in the list?
    – Leafzer
    Sep 20, 2021 at 19:21

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.