"Gregory Piñero" <[EMAIL PROTECTED]> schrieb im Newsbeitrag
news:[EMAIL PROTECTED]
|And here is how I make sure I'm always using the right directory in my
scripts:
|
|Put this code at the top:
|import sys
|curdir=os.path.dirname(sys.argv[0])
|#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
<snipped>
Greg,
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
try:
isFrozen = sys.frozen
except AttributeError:
pass
if isFrozen:
appPrefix = os.path.split(sys.executable)[0]
else:
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.
Regards,
--
Vincent Wehren
--
http://mail.python.org/mailman/listinfo/python-list