0

Here is my code so far.

def pfunc():
    portList = []
    user_choice_port = userPort.get()
    portList.append(user_choice_port)

the userPort is basically a text variable for what the user will enter into an entry box (which will be ports). The user will enter the port numbers like this:

23, 80, 44, etc.

How do I take those numbers and put them into a list. Cause whenever I do it puts them in as a string that looks like this:

['23, 80, 44']

When I want it to look like this:

[23,80,44]

I cannot figure this out so any help would be appreciated

1 Answer 1

1

This should help.

user_choice_port = "23, 80, 44"
print map(int, user_choice_port.split(","))
print [int(n) for n in user_choice_port.split(",")]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks this worked! But how can I .append() those results to a list? Like if I had a list called portList = []. How could I take an input and then just .append() them straight into it?

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.