Re: [Tutor] reference to directory a module is located at

2009-06-18 Thread Elisha Rosensweig
Thanks - just what I needed (and thanks to all the others too)

Elisha

On Thu, Jun 18, 2009 at 12:48 PM, Dave Angel  wrote:

> bob gailer wrote:
>
>  Elisha Rosensweig wrote:
>>
>>> > Hi,
>>> >
>>> > How can I determine the directory in which a module is located, from >
>>> within that module?
>>>
>>>
>> sys.modules[__name__].__file__
>> -- Bob Gailer
>>
> Or more simply,
>   __file__
>
> But the OP wanted the directory, which can be extracted with method
> dirname:
>
> import os
> print __file__
> print os.path.dirname(__file__)
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reference to directory a module is located at

2009-06-18 Thread Strax-Haber, Matthew (LARC-D320)
Whoops. I should read more carefully. I thought he said the path to the module 
itself. Yes, os.path.dirname(__file__) works.
If you want an absolute path (rather than a relative path), use:
os.path.abspath(os.path.dirname(__file__))
I would find this more useful if the path will be passed around.
--
~ Matthew Strax-Haber
National Aeronautics and Space Administration
Langley Research Center (LaRC)
Co-op, Safety-Critical Avionics Systems Branch
Student, Northeastern University
W: 757-864-7378; C: 561-704-0029
matthew.strax-ha...@nasa.gov



From: Dave Angel 
Date: Thu, 18 Jun 2009 11:48:40 -0500
To: Python Tutor 
Subject: Re: [Tutor] reference to directory a module is located at

bob gailer wrote:

> Elisha Rosensweig wrote:
>> > Hi,
>> >
>> > How can I determine the directory in which a module is located, from
>> > within that module?
>>
> sys.modules[__name__].__file__
> -- Bob Gailer
Or more simply,
__file__

But the OP wanted the directory, which can be extracted with method dirname:

import os
print __file__
print os.path.dirname(__file__)


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reference to directory a module is located at

2009-06-18 Thread Strax-Haber, Matthew (LARC-D320)
Try the following:
import os.path
os.path.abspath(__file__)
This won't work in an interactive shell since it is not being executed from 
within a module.
--
~ Matthew Strax-Haber
National Aeronautics and Space Administration
Langley Research Center (LaRC)
Co-op, Safety-Critical Avionics Systems Branch
Student, Northeastern University
W: 757-864-7378; C: 561-704-0029
matthew.strax-ha...@nasa.gov



From: Elisha Rosensweig 
Reply-To: 
Date: Thu, 18 Jun 2009 11:17:56 -0500
To: Python Tutor 
Subject: [Tutor] reference to directory a module is located at

Hi,

How can I determine the directory in which a module is located, from within 
that module?

Elisha

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reference to directory a module is located at

2009-06-18 Thread Dave Angel

bob gailer wrote:


Elisha Rosensweig wrote:

> Hi,
>
> How can I determine the directory in which a module is located, from 
> within that module?


sys.modules[__name__].__file__
-- Bob Gailer

Or more simply,
   __file__

But the OP wanted the directory, which can be extracted with method dirname:

import os
print __file__
print os.path.dirname(__file__)


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] reference to directory a module is located at

2009-06-18 Thread bob gailer

Elisha Rosensweig wrote:

Hi,

How can I determine the directory in which a module is located, from 
within that module?

sys.modules[__name__].__file__

--
Bob Gailer
Chapel Hill NC
919-636-4239
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] reference to directory a module is located at

2009-06-18 Thread Elisha Rosensweig
Hi,

How can I determine the directory in which a module is located, from within
that module?

Elisha
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor