py2exe windows apps path question

vincent wehren vincent at
Tue Aug 2 20:21:29 CEST 2005

"Gregory Piñero" <gregpinero at> schrieb im Newsbeitrag 
news:mailman.2632.1123005673.10512.python-list at

|And here is how I make sure I'm always using the right directory in my 
|Put this code at the top:
|import sys
|#print curdir
|Then I use curdir to build all of the paths in my app:
|For example let's get a list of files in a folder:
|lstresumes=os.listdir(os.path.join(curdir,resume_folder_path)) #get
|list of resumes



If you need something that works both on a frozen app as well as an 
(unfrozen) python
script, you'd be better off using something like:

def getAppPrefix():
    """Return the location the app is running from
    isFrozen = False
        isFrozen = sys.frozen
    except AttributeError:
    if isFrozen:
        appPrefix = os.path.split(sys.executable)[0]
        appPrefix = os.path.split(os.path.abspath(sys.argv[0]))[0]
    return appPrefix

Now you can use the return value of getAppPrefix() everywhere you need to 
calculate paths relative to your app, regardless if it involves a regular 
script or py2exe'ified one.



Vincent Wehren

More information about the Python-list mailing list