__file__ vs __FILE__

Jeff McNeil jeff at jmcneil.net
Sat Nov 3 16:24:55 CET 2007


I'm using Mac OS X, and it get:

Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> import os
 >>> os.getcwd()
'/Users/jeff'
 >>> os.path.realpath(os.path.pardir)
'/Users'
 >>>

The __file__ construct is fine from within a module and is probably  
more inline with what the OP was looking for anyways.

On Nov 3, 2007, at 7:18 AM, Bjoern Schliessmann 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_....
>
> -- 
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list