[Tutor] Script Name/Path Information

Josh Rosen rosenville at gmail.com
Sat Jul 5 23:05:10 CEST 2008


How about the following:

import os
print os.path.abspath(__file__)		# the full absolute path to the  
current module's file
print os.path.split(os.path.abspath(__file__))		# if you need the  
individual components of the path.


On Jul 5, 2008, at 11:00 AM, Monika Jisswel wrote:

> import sys      #a module that gives access to the system
> import os        #a module that gives access to the os
>
> print sys.argv[0]   #prints file name of the script
> print os.getcwd()   #print current working directory
> print os.getcwd()+sys.argv[0]   #
>
>
>
>
> 2008/7/5 Nathan Farrar <nathan.farrar at gmail.com>:
> I'm new to python and wondering if there is a way to reference  
> information about the script that is running.  For example, if I was  
> running a script named "FileInfo.py" from the directory "/home/ 
> username", I'm looking for attributes such that something similar to:
>
> print self.name
> print self.path
>
> would output:
>
> FileInfo.py
> /home/username
>
> ... Thanks!
> Nathan
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080705/ca2bb18a/attachment.htm>


More information about the Tutor mailing list