What Is Wrong With This Input Code?? And Browser Launcher In Python
this is the code ...................................................when it runs it will only run the redditNeed == 1 and it opens 5 windows. And then when i hit any other the o
Solution 1:
A couple of things:
- You should use
raw_input
; - You should only
import webbrowser
once, at the top of the script; - Rather than branching
elif
s, use a dictionary to hold the options; and - You can use
webbrowser.open
'snew
argument to try to open a new tab.
Putting that together:
import webbrowser
reddits = {1: {"name": "Front Page", "url": "http://reddit.com"}, ...}
print("Which Reddit do you want?")
for r insorted(reddits):
print("{0}. {1[name]}".format(r, reddits[r])
reddit_need = int(raw_input("Enter a number: "))
webbrowser.open(reddits[reddit_need]["url"], 2)
Post a Comment for "What Is Wrong With This Input Code?? And Browser Launcher In Python"