On Fri, 1 Oct 2010 21:00:02 +0200
Sébastien Barthélemy wrote:
> Hi,
>
> Arnaud, Christian, thank you for your help.
>
> I'll use abspath, it's shorter.
>
> Any idea why it's sometimes absolute, sometimes not?
AFAICT, that's because sys.path contains some absolute paths and some
relative ones.
Hi,
Arnaud, Christian, thank you for your help.
I'll use abspath, it's shorter.
Any idea why it's sometimes absolute, sometimes not?
--
http://mail.python.org/mailman/listinfo/python-list
Sébastien Barthélemy writes:
> Hello,
Hi!
> I use a data file that lies on disk in the same directory that the
> module which makes use of it.
>
> The data file is checked in the repository and gets installed by
> the distutils ``package_data`` directive, so it is in place both
> during develop
Am 01.10.2010 13:00, schrieb Sébastien Barthélemy:
> Hello,
>
> I use a data file that lies on disk in the same directory that the
> module which makes use of it.
>
> The data file is checked in the repository and gets installed by
> the distutils ``package_data`` directive, so it is in place bot
I think I have figured this out, thanks for your input.
The time comes from lazy modules related to e-mail importing on
attribute access, which is acceptable. Hence of course
why ImportError was sometime raised.
I originally was thinking that accessing __file__ was triggering some
mechanism that
En Fri, 05 Jun 2009 00:12:25 -0300, John Machin
escribió:
> (2) This will stop processing on the first object in sys.modules that
> doesn't have a __file__ attribute. Since these objects aren't
> *guaranteed* to be modules,
Definitely not guaranteed to be modules. Python itself drops non-mo
Steven D'Aprano REMOVE.THIS.cybersource.com.au> writes:
>
> On Fri, 05 Jun 2009 02:21:07 +, Steven D'Aprano wrote:
>
> > You corrected this to:
> >
> > for module in sys.modules.itervalues():
> >try:
> >path = module.__file__
> >except (AttributeError, Impor
Zac Burns wrote:
The section of code below, which simply gets the __file__ attribute of
the imported modules, takes more than 1/3 of the total startup time.
Given that many modules are complicated and even have dynamic
population this figure seems very high to me. it would seem very high
if one j
On Fri, 05 Jun 2009 02:21:07 +, Steven D'Aprano wrote:
> You corrected this to:
>
> for module in sys.modules.itervalues():
>try:
>path = module.__file__
>except (AttributeError, ImportError):
>return
>
> (1) You're not importing anything insid
En Thu, 04 Jun 2009 22:24:48 -0300, Zac Burns escribió:
The section of code below, which simply gets the __file__ attribute of
the imported modules, takes more than 1/3 of the total startup time.
Given that many modules are complicated and even have dynamic
population this figure seems very hig
On Thu, 04 Jun 2009 18:24:48 -0700, Zac Burns wrote:
> The section of code below, which simply gets the __file__ attribute of
> the imported modules, takes more than 1/3 of the total startup time.
How do you know? What are you using to time it?
[...]
> From once python starts and loads the main
Sorry, there is a typo. The code should read as below to repro the problem:
for module in sys.modules.itervalues():
try:
path = module.__file__
except (AttributeError, ImportError):
return
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
>
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
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
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:
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
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'
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.)
>
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
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
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
On Apr 11, 6:55 am, "John Machin" <[EMAIL PROTECTED]> wrote:
> On Apr 11, 8:03 pm, "7stud" <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi,
>
> > Thanks for the response.
>
> > On Apr 11, 12:49 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
> > wrote:
>
> > > __file__ corresponds to the filename used to locat
On Apr 11, 8:03 pm, "7stud" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Thanks for the response.
>
> On Apr 11, 12:49 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
> wrote:
>
>
>
> > __file__ corresponds to the filename used to locate and load the module,
> > whatever it is. When the module is found on the
Hi,
Thanks for the response.
On Apr 11, 12:49 am, "Gabriel Genellina" <[EMAIL PROTECTED]>
wrote:
>
> __file__ corresponds to the filename used to locate and load the module,
> whatever it is. When the module is found on the current directory
> (corresponding to '' in sys.path), you get just t
En Tue, 10 Apr 2007 21:20:51 -0300, 7stud <[EMAIL PROTECTED]>
escribió:
> I'm having trouble understanding what the definition of __file__ is.
> With this program:
>
> --
> #data.py:
>
> def show():
> print __file__
>
> if __name__ == "__main__":
> show()
> ---
>
> if I run data.
26 matches
Mail list logo