[Tutor] how do I find where my program is installed?

Bill Burns billburns at pennswoods.net
Fri Sep 8 00:27:27 CEST 2006


[Jeff]
> I read the link you sent, and I am not sure what they mean by "You 
> cannot rely on __file__, because __file__ is not there in the py2exed 
> main-script." can't I use _file_ in my application though? This is what 
> I just added to my application and it seems to do the trick... is there 
> an exception that I am not aware of?

[Bill]
Apparently, py2exe does something (when it freezes the script), which
makes __file__ break or at least makes it unreliable. What that
something is, I have know idea. Someone else on the list may know...

[Jeff]
> using your method, what do you do with 'installDir' in py2exe?
> 

[Bill]
The documentation for my program lives in a sub-directory of the program
directory.

Example: C:\Program Files\FilePrinter\documentation

But the 'program directory' could be anywhere the user felt like 
installing it, so...

when a user wants to open the docs, they click on a menu item in the GUI
and this code gets fired:

def on_openDocs_command(self, event):
         """Opens the documention."""
         installDir = os.path.dirname(os.path.abspath(sys.argv[0]))
         docs = r'documentation\FilePrinter.html'
         webbrowser.open(os.path.join(installDir, docs))


and no matter where they installed my program, it's possible for me to
find the file 'FilePrinter.html' and open it.

HTH

Bill




More information about the Tutor mailing list