__file__ vs __FILE__

klenwell klenwell at gmail.com
Sat Nov 3 14:51:56 EDT 2007


On Nov 3, 4:18 am, Bjoern Schliessmann <usenet-
mail-0306.20.chr0n... at spamgourmet.com> wrote:
> Jeff McNeil wrote:
> > I've used the 'os.path.realpath(os.path.pardir)' construct in a
> > couple of scripts myself.
>
> In Windows? Using Linux, this gives me "..".
>
> I use os.path.dirname(os.path.abspath(__file__))
>
> > That ought to work within the interactive interpreter.
>
> Why do you also enter that code in the interpreter? If it is in a
> module, you should always be able to use __file__.
>
> Regards,
>
> Björn
>
> --
> BOFH excuse #238:
>
> You did wha... oh _dear_....


> I use os.path.dirname(os.path.abspath(__file__))

That makes sense, as it is almost a literal translation of what I'm
used to using in PHP.  Thanks for pointing this out.




More information about the Python-list mailing list