Re: [cx-freeze-users] Can't build Win32GUI application
Brought to you by:
atuining
From: Stephen G. <elg...@gm...> - 2013-02-17 00:56:33
|
On 17/02/13 11:43, Mike Stoler wrote: > Thanks again, Thomas. That works. By importing re, I'm able to build a > simple application. Now I'm focusing on my references to __file__. My > uses range from trivial to less important than that. :-) hi mike. several of the freezsing mechanisms set an attribute 'frozen' on the sys module, you can use it to do different stuff if the app is frozen or not. for example here is a method i use to get the dir the app files are in whether or not the app is frozen: def get_program_dir(self): """ return the filesystem directory where the app program file resides (ie. the applications exec or import directory). """ if hasattr(sys,'frozen'): #app is frozen or bundled with py2app or py2exe or cxfreeze self.bundled=True app_dir=os.path.dirname(sys.executable) else: self.bundled=False if __name__ != '__main__': # we were imported app_dir=os.path.dirname(__file__) else: # we were exec'ed app_dir=os.path.abspath(sys.path[0]) return app_dir hope you can derive something useful from that info. stephen. > > > 1. (Trivial) Related file names. > > I want some filenamesto have the > same name part as my script. For instance, a typical source file > '<source>.py' might have an associated data file as '<source>.dat' and > produce a log file '<source>.log.txt'. I could hard code the value of > '<source>', but I'd prefer to have the running script figure this out > for itself. > > s_file_without_ext, _s_ext = os.path.splitext(__file__) > s_profile = s_file_without_ext + ".dat" > s_logfile = s_file_without_ext + ".log.txt" > > > 2. (Less important) - Change directory so relative file paths work "right" > > I'm using the IDLE interpreter to develop my script. When it launches, > the current working directory is always 'D:\Python33'. When my > application encounters a relative directory path, I'd like it to be > relative to where the script is running, so the first thing it does is > to change directory: > > os.chdir(os.path.dirname(__file__)) > > > Since '__file__' isn't availble, is there another way an executable / > script can inquire what it's name is? > > Thanks, > > Mike > > > ------------------------------------------------------------------------------ > The Go Parallel Website, sponsored by Intel - in partnership with Geeknet, > is your hub for all things parallel software development, from weekly thought > leadership blogs to news, videos, case studies, tutorials, tech docs, > whitepapers, evaluation guides, and opinion stories. Check out the most > recent posts - join the conversation now. http://goparallel.sourceforge.net/ > > > > _______________________________________________ > cx-freeze-users mailing list > cx-...@li... > https://lists.sourceforge.net/lists/listinfo/cx-freeze-users > |