Need help with TCP/IP client access from Windows

Bill Tutt billtut at microsoft.com
Fri Jul 30 19:17:44 EDT 1999


> From: Bill Tutt 
> 
> > From: Eric S. Raymond [mailto:esr at thyrsus.com]
> > 
> > 
> > Gordon McMillan <gmcm at hypernet.com>:
> > > > OK.  Will giving the filename ".\\intriguer" work for 
> this?  And,
> > > > given that the filename is going through the C library, 
> > will leaving
> > > > it as "./intriguer" work?
> > > 
> 
> Well, as long as your current working directory is what you 
> want it to be, sure it'll work, otherwise you'll need to pull 
> the standard "where did I get run from" nonsense.
> 

Something like the following usually does the trick:
import os
import sys

(head, tail) = os.path.split(sys.argv[0])
# If tail is None, then we just got invoked in the current working
directory.
if tail is None:
	path = os.getcwd()
else:
# Otherwise, head now contains a possibly relative path to where we were 
# invoked from, normalize it.
	path = os.sys.abspath(head)
inifile = open('%s/blah.ini' % path, 'r')

Bill




More information about the Python-list mailing list