That IS an option...

```python
import inspect

...


module_path = inspect.stack()[1][0].f_globals['__file__']

```



On Wed, Feb 19, 2014 at 11:18 AM, Giampaolo Rodola' <g.rodola@gmail.com> wrote:



On Wed, Feb 19, 2014 at 6:04 PM, Oscar Benjamin <oscar.j.benjamin@gmail.com> wrote:
On 19 February 2014 16:52, Giampaolo Rodola' <g.rodola@gmail.com> wrote:
>
> The implementation is pretty straightforward:
>
> def here(concat=None):
>     """Return the absolute path of the parent directory where the
>     script is defined.
>     """
>     here = os.path.abspath(os.path.dirname(__file__))
>     if concat is not None:
>         here = os.path.abspath(os.path.join(here, concat))
>     return here

So if I do from os.path import here and get the above function what
happens when I call it in another module?

Ouch! You're right, I naively didn't take that into account. =)
I guess there are ways to inspect the caller's module name but I'm not gonna push for that.
Sorry for the noise.


_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/



--
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated."