![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0
![]() |
Question: Calling other progs
I have a question about how to have a script call other progs (ie Word, Excel) and executing them. Can anyone point me in the general direction?
__________________
~ Silicon Enhanced Pudding "It's magically delicious" |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Oct 2005
Location: Chitown
Posts: 423
Rep Power: 4
![]() |
I think that in Perl you use the ` ` and it executes the statement in the console. I am not sure but it might be similar in Phyton.
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() ![]() |
import os
os.startfile("c:/windows/notepad.exe") |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0
![]() |
Thanks
__________________
~ Silicon Enhanced Pudding "It's magically delicious" |
|
|
|
|
|
#5 | |
|
Hobbyist Programmer
|
Quote:
now sane with that code. could i configure it a little to open like a webpage or a picture on a web page? |
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() |
Of course not. Those are two separate things. Unless you have a shortcut file to a webpage or a picture, then change the link in my code to that shortcut.
Otherwise you'll have to use urllib2 and save, then open, the output. import urllib2 import os # load this image: image_in = "http://us.i1.yimg.com/us.yimg.com/i/ww/beta/y3.gif" # save it as: image_out = "my_image.gif" # prepare the opener for opening web pages opener = urllib2.build_opener() # load the image in to a string page = opener.open(image_in) image = page.read() # open the stream with binary mode enabled stream = open(image_out, "wb") stream.write(image) stream.close() # open the image os.startfile(image_out) |
|
|
|
|
|
#7 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Firstly, bear in mind os.startfile is Windows specific (it won't work on Mac or Linux if you try to run your script there).
Sane: may be better if you mentioned it's win-only before you advocated its adoption. Quote:
import webbrowser
# open the webpage
webbrowser.open("http://google.com")
# open an image in the browser
webbrowser.open("http://www.google.com/intl/en/images/logo.gif") |
|
|
|
|
|
|
#8 | |
|
Newbie
Join Date: Jun 2006
Location: In a box
Posts: 27
Rep Power: 0
![]() |
Quote:
__________________
~ Silicon Enhanced Pudding "It's magically delicious" |
|
|
|
|
|
|
#9 |
|
Programming Guru
![]() ![]() |
Use os.environ['OS'] or os.name to determine if it's linux. Then os.system("command") with the appropriate command that would be used to execute the program via linux command line.
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
FYI, os.environ['OS'] doesn't work on my mac, while os.name does.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|