简体   繁体   中英

Python: webbrowser.open(“”) opens a file explorer window

I'm coding a very simple url opener that gets the url in the terminal window (using input ) and opens it with webbrowser.open .

The problem is that when nothing is put into the input (it's run webbrowser.open("") ), a file explorer window appears instead of my web browser, and when I put something in the input, for example, http://www.google.com (it's run webbrowser.open("http://www.google.com") ) it correctly opens google chrome. What's happening?

I'm running python 3.2.2 on windows 8, AMD. Thanks in any advance.

Well, on the Python webpage for the webbrowser module, under webbrowser.open() , it says

Note that on some platforms, trying to open a filename using this function, may work and start the operating system's associated program.

Your computer realizes that you aren't trying to open a URL, so it attempts to open a file instead and because there is no input, it just opens your file explorer.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM