__file__ vs __FILE__
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sat Nov 3 10:46:35 EDT 2007
En Sat, 03 Nov 2007 10:07:10 -0300, Giampaolo Rodola' <gnewsg 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
More information about the Python-list
mailing list