[Tutor] Selecting a browser

Ricardo Aráoz ricaraoz at gmail.com
Tue Dec 4 05:51:52 CET 2007


Martin Walsh wrote:
> Ricardo Aráoz wrote:
>> Martin Walsh wrote:
>> Hi Marty, thanks for your help.
>> I've tried your suggestions but they don't seem to work for me. In W's
>> system window I can do :
>> C:/> S:\FirefoxPortable\FirefoxPortable.exe http://www.google.com
>> and it will open my browser ok. But no matter what I try :
>> "c:/program files/mozilla firefox/firefox.exe %s &" or "c:/program
>> files/mozilla firefox/firefox.exe %s" as input to webbrowser.get() it
>> won't work.
> 
> Hi Ricardo,
> 
> Never would have guessed that you were using a portable browser :) But
> it really shouldn't matter. And by the way, the '&' has special meaning
> to the webbrowser.get method -- it determines whether a
> BackgroundBrowser or GenericBrowser object is returned.

LOL, another demerit to documentation.
I not only use a portable browser, it's inside a TrueCrypt volume in my
pen drive. That means I'm not restrained to my company's choices on
browsers or their settings, and I get 'some' degree of privacy.


> 
>> Here's my session :
>>
>>>>> import webbrowser
>>>>> ff = webbrowser.get("S:\FirefoxPortable\FirefoxPortable.exe %s &")
>>>>> ff.open('http://www.google.com')
>> False
> 
> I suspect (with no way to confirm at the moment) that something in the
> webbrowser module is confused by the backslashes. As you may know, the
> backslash has special meaning in python strings, used as an escape
> character to denote newlines (\n), tabs (\t), among others. I believe it
> is helpful to be aware of this when using subprocess.Popen also. And, I
> think you have more than one option for dealing with slashes in windows
> paths, but I typically just replace the backslashes with forward slashes:
> 
> ff = webbrowser.get("S:/FirefoxPortable/FirefoxPortable.exe %s &")
> 

That did it, but as I told Kent :

ff.open('http://www.google.com')
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "E:\Python25\lib\webbrowser.py", line 168, in open
    p = subprocess.Popen(cmdline, close_fds=True)
  File "E:\Python25\lib\subprocess.py", line 551, in __init__
    raise ValueError("close_fds is not supported on Windows "
ValueError: close_fds is not supported on Windows platforms

Don't worry, I see I'll have to look into the module's code or go the
popen() way. I'll let you know.

Again, thanks a lot for your help.

Ricardo



More information about the Tutor mailing list