The folder a script is executed in

Benjamin musiccomposition at gmail.com
Wed Aug 22 22:13:57 EDT 2007


On Aug 21, 10:23 am, Benjamin <musiccomposit... at gmail.com> wrote:
> On Aug 21, 4:10 am, aine_ca... at yahoo.com wrote:> Hi,
>
> > How do I find out what folder a script is in while it is executing?
>
> > For example, for the file "C:/folder/script.py" contain the following
> > two lines of code -
>
> > myLocation = GetMyLocation()
> > print myLocation
>
> def GetMyLocation():
>     runningFile = sys.argv[0] if __name__ == "__main__" else __file__
>     return os.path.dirname(runningFile)
never mind that above
def GetMyLocation():
    if __name__ == "__main__":
         runningFile = sys.argv[0] if os.path.isabs(sys.argv[0]) else
os.path.abs(sys.argv[0])
    else:
         runningFile = __file__
    return runningFile


>
>
>
> > >> C:/folder
>
> > Thanks,
>
> > Aine.





More information about the Python-list mailing list