Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #27507

Re: Why doesn't Python remember the initial directory?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!not-for-mail
From Grant Edwards <invalid@invalid.invalid>
Newsgroups comp.lang.python
Subject Re: Why doesn't Python remember the initial directory?
Date Mon, 20 Aug 2012 16:28:59 +0000 (UTC)
Organization PANIX Public Access Internet and UNIX, NYC
Lines 46
Message-ID <k0tokb$arb$1@reader1.panix.com> (permalink)
References <k0rj38$2gc$1@reader1.panix.com> <roy-CA6D77.17031119082012@news.panix.com> <k0s5iq$seh$1@reader1.panix.com>
NNTP-Posting-Host dsl.comtrol.com
X-Trace reader1.panix.com 1345480139 11115 64.122.56.22 (20 Aug 2012 16:28:59 GMT)
X-Complaints-To abuse@panix.com
NNTP-Posting-Date Mon, 20 Aug 2012 16:28:59 +0000 (UTC)
User-Agent slrn/pre1.0.0-18 (Linux)
Xref csiph.com comp.lang.python:27507

Show key headers only | View raw


On 2012-08-20, kj <no.email@please.post> wrote:
> In <roy-CA6D77.17031119082012@news.panix.com> Roy Smith <roy@panix.com> writes:
>
>>In article <k0rj38$2gc$1@reader1.panix.com>, kj <no.email@please.post> 
>>wrote:
>
>>> As far as I've been able to determine, Python does not remember
>>> (immutably, that is) the working directory at the program's start-up,
>>> or, if it does, it does not officially expose this information.
>
>>Why would you expect that it would?  What would it (or you) do with this 
>>information?
>
> This means that no library code can ever count on, for example,
> being able to reliably find the path to the file that contains the
> definition of __main__.

What makes you think that the file that contains the definition of
__main__ is the working directory on program startup?  That's almost
never the case in my experience.

2) Why should a library expect to be able to access the file
   containing the definition of __main__.  

> That's a weakness, IMO.

You must be in possession of some rather odd use cases.  I've been
writing Python programs for something like 13 years, and I've never
felt any need to have either an immutable record of the startup
directory or access to the file containing the definition of __main__.

> I don't know of any way to fix inspect.getmodule that does not
> involve, directly or indirectly, keeping a stable record of the
> starting directory.

If what you really want is access to the definition of __main__, what
does that have to do with the startup directory?

If you want to know where __main__ is, you can probably figure it out
from /proc/self/<something-or-other>


-- 
Grant Edwards               grant.b.edwards        Yow! Am I having fun yet?
                                  at               
                              gmail.com            

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Why doesn't Python remember the initial directory? kj <no.email@please.post> - 2012-08-19 20:42 +0000
  Re: Why doesn't Python remember the initial directory? Giacomo Alzetta <giacomo.alzetta@gmail.com> - 2012-08-19 14:01 -0700
    Re: Why doesn't Python remember the initial directory? Nobody <nobody@nowhere.com> - 2012-08-20 01:45 +0100
      Re: Why doesn't Python remember the initial directory? Neil Hodgson <nhodgson@iinet.net.au> - 2012-08-21 11:39 +1000
  Re: Why doesn't Python remember the initial directory? Roy Smith <roy@panix.com> - 2012-08-19 17:03 -0400
    Re: Why doesn't Python remember the initial directory? kj <no.email@please.post> - 2012-08-20 01:57 +0000
      Re: Why doesn't Python remember the initial directory? Jerry Hill <malaclypse2@gmail.com> - 2012-08-19 22:05 -0400
      Re: Why doesn't Python remember the initial directory? alex23 <wuwei23@gmail.com> - 2012-08-19 19:57 -0700
        Re: Why doesn't Python remember the initial directory? alex23 <wuwei23@gmail.com> - 2012-08-19 20:04 -0700
          Re: Why doesn't Python remember the initial directory? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-20 08:11 +0100
        Re: Why doesn't Python remember the initial directory? alex23 <wuwei23@gmail.com> - 2012-08-19 20:03 -0700
        Re: Why doesn't Python remember the initial directory? alex23 <wuwei23@gmail.com> - 2012-08-19 19:59 -0700
        Re: Why doesn't Python remember the initial directory? Paul Rubin <no.email@nospam.invalid> - 2012-08-20 21:20 -0700
      Re: Why doesn't Python remember the initial directory? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-20 03:38 +0000
        Re: Why doesn't Python remember the initial directory? alex23 <wuwei23@gmail.com> - 2012-08-19 20:43 -0700
      Re: Why doesn't Python remember the initial directory? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-20 08:10 +0100
      Re: Why doesn't Python remember the initial directory? andrea crotti <andrea.crotti.0@gmail.com> - 2012-08-20 12:56 +0100
        Re: Why doesn't Python remember the initial directory? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-20 13:14 +0000
          Re: Why doesn't Python remember the initial directory? Walter Hurry <walterhurry@lavabit.com> - 2012-08-20 13:49 +0000
            Re: Why doesn't Python remember the initial directory? Roy Smith <roy@panix.com> - 2012-08-20 09:58 -0400
              Re: Why doesn't Python remember the initial directory? andrea crotti <andrea.crotti.0@gmail.com> - 2012-08-20 15:15 +0100
      Re: Why doesn't Python remember the initial directory? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-08-20 16:39 +0200
      Re: Why doesn't Python remember the initial directory? Grant Edwards <invalid@invalid.invalid> - 2012-08-20 16:28 +0000
      Re: Why doesn't Python remember the initial directory? Piet van Oostrum <piet@vanoostrum.org> - 2012-08-20 16:06 -0400
      Re: Why doesn't Python remember the initial directory? John Roth <johnroth1@gmail.com> - 2012-08-21 13:35 -0700
  Re: Why doesn't Python remember the initial directory? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-19 22:18 +0100
  Re: Why doesn't Python remember the initial directory? Laszlo Nagy <gandalf@shopzeus.com> - 2012-08-19 23:05 +0200
  Re: Why doesn't Python remember the initial directory? 88888 Dihedral <dihedral88888@googlemail.com> - 2012-08-19 17:54 -0700

csiph-web