[Tutor] What's wrong with this?

Andreas Kostyrka andreas at kostyrka.org
Sat May 5 02:06:55 CEST 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Andre Roberge wrote:
> Perhaps the following might be helpful:
> 
> http://groups.google.com/group/comp.lang.python/browse_thread/thread/f1b60f4739591d6b/4417f807848b4b5d?lnk=gst&q=launching&rnum=4#4417f807848b4b5d
> 
> (if the link does not work, google for "launching python program
> cross-platform" or go to
> http://aspn.activestate.com/ASPN/Mail/Message/python-list/3467794)
> André
> 
> On 5/3/07, Jason Coggins <jcoggins828 at charter.net> wrote:
>>
>> I have the following function in a program:
>>
>> os.popen('filename.py')
>>
>> What I want to do is launch the program in the os.popen() function.  The
>> file I am trying to launch is located in the same directory as the program
>> the function is contained in.  I also use Linux if that makes a difference.

Well, first the current directory might not be the same as the directory
where the script is stored.

So you need something like this:

import os, sys

fp = op.popen(os.path.join(os.path.dirname(sys.argv[0]), "filename.py", "r")

Andreas

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGO8qfHJdudm4KnO0RAvYTAKCtBp5ALtTWgtOCCbMfTBdqU7z71wCgxfNf
FBkdKEoHOWX5c09Ru+bApcY=
=J9pa
-----END PGP SIGNATURE-----


More information about the Tutor mailing list