Size: 643
Comment: converted to 1.6 markup
|
Size: 698
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
See also WhereAmI for another take on this problem. |
See also WhereAmI for another take on this problem.
ThomasHeller posted this tip to the mailing list:
main_is_frozen() returns True when running the exe, and False when running from a script.
get_main_dir() returns the directory name of the script or the directory name of the exe - this is also sometimes useful.
1 import imp, os, sys
2
3 def main_is_frozen():
4 return (hasattr(sys, "frozen") or # new py2exe
5 hasattr(sys, "importers") # old py2exe
6 or imp.is_frozen("__main__")) # tools/freeze
7
8 def get_main_dir():
9 if main_is_frozen():
10 return os.path.dirname(sys.executable)
11 return os.path.dirname(sys.argv[0])