1

I want to copy and paste some link (I tell it, how much), into this console program, and this will open it for me. I created a for loop so it will ask for a link (once if I typed 1...). But it is trying to execute and open the link every time when I paste a link. A want it at the end. How can I do it? (I was trying some things, but it isn't working).

import webbrowser as wb
number = int(input(':'))
for x in (numbers+1 for numbers in range(number)):
    globals()["link"+str(x)] = input("Link: ")
    wb.get('edge').open(link1,link2....)

This will store the links in "link1", "link2". But I don't know how to tell to try link1 in the command, link2.... And when it can't be execute than stop. (I set up the wb.register thing, it's working).

1
  • 6
    Whoever gave you the idea with globals()["link"+str(x)]: In the future try to avoid their programming tips. Commented Oct 27, 2020 at 11:10

1 Answer 1

1

You'll want to put the links in a list, then open them afterwards.

I've changed the logic here to not ask you for a number of links beforehand; just enter an empty string to have it open the links.

import webbrowser as wb

links = []
while True:
    link = input(f"Enter link {len(links) + 1} or empty to open all links:")
    if not link:
        break
    links.append(link)

for link in links:
    wb.get("edge").open(link)
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.