__file__ vs __FILE__

Giampaolo Rodola' gnewsg at gmail.com
Mon Nov 5 01:09:20 CET 2007


On 3 Nov, 15:46, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> En Sat, 03 Nov 2007 10:07:10 -0300, Giampaolo Rodola' <gne... at gmail.com>  
> escribió:
>
> > On 3 Nov, 04:21, klenwell <klenw... at gmail.com> wrote:
> >> In PHP you have the __FILE__ constant which gives you the value of the
> >> absolute path of the file you're in (as opposed to the main script
> >> file.)
> > This is not really 'one-line' since you have to import two modules
> > first, but it looks nicer...:
>
> > import sys, os
> > print sys.argv[0] # absolute file name
> > print os.path.dirname(sys.argv[0]) # absolute dir name
>
> Note that this returns the location of the *main* script, not the current  
> module, as the OP explicitely asked for.
>
> --
> Gabriel Genellina

Whoops! You're right.




More information about the Python-list mailing list