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).

LucioRandy
  • 220
  • 1
  • 19
  • 6
    Whoever gave you the idea with `globals()["link"+str(x)]`: In the future try to avoid their programming tips. – Matthias Oct 27 '20 at 11:10

1 Answers1

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)
AKX
  • 152,115
  • 15
  • 115
  • 172