Re: __file__ vs __FILE__

2007-11-05 Thread Matimus
On Nov 5, 1:07 am, sandipm <[EMAIL PROTECTED]> wrote: > interestingly... > I wanted to reuse this code so i wrote function in a file > > def getParentDir(): > import os > return os.path.dirname(os.path.abspath(__file__)) > > and called this function, in another file, its giving me parent >

Re: __file__ vs __FILE__

2007-11-05 Thread sandipm
interestingly... I wanted to reuse this code so i wrote function in a file def getParentDir(): import os return os.path.dirname(os.path.abspath(__file__)) and called this function, in another file, its giving me parent directory of file where this function is defined.? how to reuse this

Re: __file__ vs __FILE__

2007-11-04 Thread Giampaolo Rodola'
On 3 Nov, 15:46, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Sat, 03 Nov 2007 10:07:10 -0300, Giampaolo Rodola' <[EMAIL PROTECTED]> > escribió: > > > On 3 Nov, 04:21, klenwell <[EMAIL PROTECTED]> wrote: > >> In PHP you have the __FILE__ constant which gives you the value of the > >> absol

Re: __file__ vs __FILE__

2007-11-03 Thread Bjoern Schliessmann
klenwell wrote: > Bjoern Schliessmann wrote: >> 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. You're welcome, happy coding :) Regards, Björn -- BOFH excuse #286:

Re: __file__ vs __FILE__

2007-11-03 Thread klenwell
On Nov 3, 4: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

Re: __file__ vs __FILE__

2007-11-03 Thread Jeff McNeil
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'

Re: __file__ vs __FILE__

2007-11-03 Thread Gabriel Genellina
En Sat, 03 Nov 2007 10:07:10 -0300, Giampaolo Rodola' <[EMAIL PROTECTED]> escribió: > On 3 Nov, 04:21, klenwell <[EMAIL PROTECTED]> 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.) >

Re: __file__ vs __FILE__

2007-11-03 Thread Giampaolo Rodola'
On 3 Nov, 04:21, klenwell <[EMAIL PROTECTED]> wrote: > I apologize in advance for coming at this from this angle but... > > 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.) With the function dirname

Re: __file__ vs __FILE__

2007-11-03 Thread Bjoern Schliessmann
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 cod

Re: __file__ vs __FILE__

2007-11-02 Thread Jeff McNeil
The __file__ attribute is present when you run a script from a file. If you run from the interactive interpreter, it will raise a NameError. Likewise, I believe that in earlier versions of Python (2.1? Pre 2.2?) it was only set within imported modules. I've used the 'os.path.realpath(os.pat

__file__ vs __FILE__

2007-11-02 Thread klenwell
I apologize in advance for coming at this from this angle but... 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.) With the function dirname, this makes it easy to get the parent dir of a particular fil