I got the foundation and ideas for this online. It works great when I run it in Windows 10 but not Ubuntu 16.04. On Ubuntu it mistakes the URL for a file and gives me a file not found error. Is this a user coding error, a Ubuntu problem, or a Python problem?
To be a bit more specific it is a gvfs-open error.
import webbrowser
new = 2
choice = raw_input('Type site name:\n> ')
site = choice
url1 = 'www..com'
url = url1[:4] + site + url1[4:]
webbrowser.open(url,new=new)
Here are the results.
$ gvfs-open: www.google.com: error opening location: error when getting information for file '/home/username/Documents/www.google.com: no such file or directory
I took Klaus D. advice and added http://
. Now it works on both OSs. Thank you!
import webbrowser
new = 2
choice = raw_input('Type site name:\n> ')
site = choice
url1 = 'www..com'
url = 'http://' + url1[:4] + site + url1[4:]
webbrowser.open(url,new=new)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.