[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-ideas
Subject:    Re: [Python-ideas] os.path.here()
From:       Oscar Benjamin <oscar.j.benjamin () gmail ! com>
Date:       2014-02-19 17:35:25
Message-ID: CAHVvXxT9U4+h9vAOOJ3+f+Oo2uWknDzKEVs8Fp+Utz5em1gsrA () mail ! gmail ! com
[Download RAW message or body]

On 19 February 2014 17:18, 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.

There are ways to do it. namedtuple does it here:
http://hg.python.org/cpython/file/e6016fffc894/Lib/collections/__init__.py#l374

But I think that's considered to be an unfortunate mistake by some.


Oscar
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic