Reputation: 5514
So I have a Python script which I make into an exe
with py2exe and I want it to do certain tasks only when the exe
version is running. Is there a way to write the code so I don't have to manually save a separate version before I create the exe
?
I'm picturing something like this:
if self.filename[-4:] == ".exe":
do this code
So it would somehow be able to find its own file name. Can it be done?
Upvotes: 1
Views: 82
Reputation: 37319
The py2exe docs give a way to do this:
http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
import imp, os, sys
def main_is_frozen():
return (hasattr(sys, "frozen") or # new py2exe
hasattr(sys, "importers") # old py2exe
or imp.is_frozen("__main__")) # tools/freeze
Upvotes: 0
Reputation: 8685
if ".exe" in self.fileName:
print "it's an exe file!"
Given that self.filename = "someprogram.exe"
Upvotes: 0