[Pythonmac-SIG] Re: Newbie path problem -- revisited, again
Ronald Oussoren
oussoren at cistron.nl
Fri Mar 19 02:51:51 EST 2004
On 19-mrt-04, at 8:33, Larry Bugbee wrote:
> Sorry.... I forgot a line. Here is the revised snippet.
>
>
> import os, sys
>
> # include next 4 lines at the very top of all Python "main" programs
> if not os.path.dirname(__file__): # perhaps sys.platform ==
> 'darwin'?
> exec('import %s' % __file__[:-3]) # assumes a '.py' suffix
> sys.exit()
> __name__ = '__main__'
>
> # test...
> if __name__ == '__main__':
> print '\n I am located at "%s" doing whatever.....\n' % __file__
What is this supposed to accomplish?
if __file__ is not an absolute path you can use
os.path.abspath(__file__) to get the full path.
BTW. If I double-click a python script that contains "print __file__"
(without the quotes) it prints the full path to the file
Ronald
More information about the Pythonmac-SIG
mailing list