Hi Stuart, it's a vague question, so all I can give is vague answers.
What OS are you using?

But - 

If your environment variables will contain info about the file, you
can use os.environ, however, that pulls all the env variables - i.e.,
on my WinXP -

>>> envVars = os.environ
>>> for (key, val) in envVars.items():
...     print key, val
...     print 
....
TMP C:\DOCUME~1\Bob\LOCALS~1\Temp

COMPUTERNAME HAL

USERDOMAIN HAL

VDMSPATH C:\Program Files\VDMSound

COMMONPROGRAMFILES C:\Program Files\Common Files

PROCESSOR_IDENTIFIER x86 Family 6 Model 2 Stepping 1, AuthenticAMD

PROGRAMFILES C:\Program Files

PROCESSOR_REVISION 0201

PATH C:\Perl\bin\;C:\WINDOWS\system32;C:\WINDOWS; 
C:\WINDOWS\System32\Wbem;C:\Program Files\VDMSound; :\python23;c:\j2sdk1.4.0\bin

SYSTEMROOT C:\WINDOWS

TEMP C:\DOCUME~1\Bob\LOCALS~1\Temp

PROCESSOR_ARCHITECTURE x86

ALLUSERSPROFILE C:\Documents and Settings\All Users

SESSIONNAME Console

HOMEPATH \

USERNAME Bob

LOGONSERVER \\HAL

COMSPEC C:\WINDOWS\system32\cmd.exe

CLASSPATH c:\javastz;c:\javastz\0_hello;c:\javastz\coscClasses;bsh.jar

PATHEXT .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH

CLIENTNAME Console

WINDIR C:\WINDOWS

APPDATA C:\Documents and Settings\Bob\Application Data

HOMEDRIVE C:

SYSTEMDRIVE C:

NUMBER_OF_PROCESSORS 1

PROCESSOR_LEVEL 6

OS Windows_NT

USERPROFILE C:\Documents and Settings\Bob

That long discretion aside,  so you can grab stuff straight from os.environ - 

>>> print os.environ['SYSTEMROOT']
C:\WINDOWS

Alternatively, you can walk your directories. 

If you have a rough idea where it might be, that's better than walking
your whole HD, but you could.

>>> for (dirpath, dirnames, filenames) in os.walk('c:/python23'):
...     if 'cmreportsnocomments.py' in filenames:
...             print 'I know this isn\'t OS safe, but I can\'t be bothered
importing os.path'
...             x = "%s\\cmreportsnocomments.py" % dirpath
...             if '/' in x:
...                     x = x.replace('/','\\')
...             print x
... 
I know this isn't OS safe, but I can't be bothered importing os.path
c:\python23\cmreportsnocomments.py
I know this isn't OS safe, but I can't be bothered importing os.path
c:\python23\tc_project\cmreportsnocomments.py

But yeah, I would recommend (if you can control your target app's
install) that you chuck a systemenv up with the installed path and go
from there.

HTH

Liam Clarke
On Mon, 14 Feb 2005 10:26:36 +0000, Stuart Murdock
<[EMAIL PROTECTED]> wrote:
> Hi
> 
> I am working from within python and want to know the best way to know if
> a certain package is installed for use on my machine.
> 
> I want to know from within python that a specific executable file is on
> my path where I could actually run the command from a prompt in a system
> shell.
> 
> I don't want to restrict exacltly where the file is and I don't want to
> do a general try catch.
> 
> Are there any simple one or two liners that anyone is aware of?
> 
> Thanks
> 
> Stuart
> 
> --
> 
> Stuart Murdock Ph.D,
> Research Fellow,
> Dept. of Chemistry / E-Science,
> University of Southampton,
> Highfield, Southampton,
> SO17 1BJ, United Kingdom
> 
> http://www.biosimgrid.org
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to