views:

59

answers:

1

How can I make the program verify if it's already on the targeted locations, and if not, move itself to another location?

A: 

os.path.abspath(__file__) is the absolute path to the current module's (or main script's) present location, and os.rename is a way to move a file (not to a location where another file of the same name is already present, though; you'd have to os.unlink the latter first).

Alex Martelli
I've read in someplace that os.path.abspath(__file__) will not work properly with compiled scripts by py2exe, it's true?
Shady
@Shady, yes, `py2exe` changes the equation (you should mention in your Q if you're using `py2exe`!). In that case, you can look at `sys.argv[0]` and if it doesn't include a directory you'll have to scan all directories on `os.environ['PATH']` to find it.
Alex Martelli