[Tutor] Re: Tutor Digest, Vol 12, Issue 71

Brian van den Broek bvande at po-box.mcgill.ca
Mon Feb 14 11:52:24 CET 2005


Lobster said unto the world upon 2005-02-14 13:32:
>  >> - I am trying to call up an external program
>  >> with something like a "Shell" command - can not find a way of doing
>  >> this
>  >> (in windows)
>  >>
>  >> Any hints?
> 
>    What about os.system('your_command_here')?
> 
> 
> =====
> 
> That is a good tip and seems to be the place I need to look
> - not really quite sure what I am looking at in the help docs
> I also have the complication of having to use is it "C:\\"
> - two back slashes?

Hi,

the doubled up backslashes are needed for using backslashes in normal 
strings as the backslash is the escape character -- the character in a 
string that says 'hey, this next one's not a normal character' and is 
how you put tabs '\t' and newlines '\n' in strings.

But, a much better option is to use '/'s -- Python's smart enough to 
get the point if you use them in file paths on windows.

> I am trying to get a wikipedia directed search that will load firefox and
> search for an inputted word . . .
> 
> 
> Anyway this is the code (only my second useful program)
> eh - not working so far . . .
> 
> usually dumbing down help appreciated
> 
> =====
> 
> Ed Jason
> 
> ========= <code>
> 
> # Wikipedia search engine
> # Sunday Feb 12
> 
> import os              
> word_sought = raw_input("What is your wikipedia search word? ")
> goto_url_location = "http://en.wikipedia.org/wiki/" +  word_sought
> print goto_url_location
> os.execv('C:\Program Files\Mozilla Firefox\firefox.exe') + 
> goto_url_location
> 
> ======== </code>

It is almost 6am here, so I won't say anything more about your code 
than that given why you are using os.execv, you should look at the 
webbrowser module instead. (webbrowser.open() would be perfect if 
firefox is your default browser, if not, I think the function is 
webbrowser.get().)

Best, and goodnight/morning all,

Brian vdB



More information about the Tutor mailing list