[Tutor] UPDATED: Question on how to open other programs andfiles
Alan Gauld
alan.gauld at btinternet.com
Mon Feb 9 10:06:44 CET 2009
"Hi" <haztang17 at gmail.com> wrote
> In short, I want to be able to read the data in the
> file as well as launch document viewer in Python. For one of the
> files I
> want to read the data from a Python script that's in the same folder
> as the
> GUI Python script.
OK, You need to be really clear about what you mean.
Do you want to run the python script and use the resultant
output as data in your script or do you want to read the
contents of the python script (variables/constants etc)?
If its the latter you could import the script.
If its the former then its exactly the same as the pdf file.
> For the pdf file I simply want to be able to launch
> document viewer from Python.
The officially approved way of doing that now is using the
subprocess module. If you want to read the output back
into your program you need to use subprocess.Popen.
If you just want to run the viewer use subprocess.call
> I know it is probably a lengthy and demanding
> request, but I just want to be able to do both
No, its quite a common requirement, it just wasn't clear if
you wanted to run the applications or to read the internal
data directly.
> I have tried to look up different tutorials online, but I have not
> found one
> that addresses my issues.
Try the Using the OS topic of my tutorial.
It shows several examples including using subprocess.Popen.
--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list