The folder a script is executed in

Ant antroy at gmail.com
Tue Aug 21 05:46:27 EDT 2007


On Aug 21, 10:29 am, aine_ca... at yahoo.com wrote:
> On 21 Aug, 11:27, Ant <ant... at gmail.com> wrote:
>
>
>
> > On Aug 21, 10:10 am, aine_ca... at yahoo.com wrote:
> > ...
>
> > > myLocation = GetMyLocation()
> > > print myLocation
>
> > > >> C:/folder
>
> > Do you mean the folder containing the script? Or the current working
> > directory?
>
> > If the former, then look at os.path.split(sys.argv[0])[0]
> > If the latter, try something like: os.path.abspath(os.curdir)
>
> > --
> > Ant...
>
> >http://antroy.blogspot.com/
>
> The following code -
>
> import os
> import sys
> print os.getcwd() + "."
> print os.path.split(sys.argv[0])[0] + "."
>
> gives me -
>
> C:\Documents and Settings\me\Desktop.
> .

Which looks correct. You've executed the code in an interactive
session launched from a desktop shortcut at a guess. You won't get the
location of the script unless you are actually running a script :-).
Of course you'll get a current working directory however you are
running python.

--
Ant...

http://antroy.blogspot.com/






More information about the Python-list mailing list