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


Groups > comp.lang.python > #27467

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

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!hq-usenetpeers.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!194.109.133.85.MISMATCH!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; '(at': 0.03; 'argument': 0.04; 'subject:Python': 0.05; 'attribute': 0.05; 'python': 0.09; '"if': 0.09; "ain't": 0.09; 'club.': 0.09; 'does,': 0.09; 'happen.': 0.09; 'information?': 0.09; 'none.': 0.09; 'path.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'script,': 0.09; 'subject:Why': 0.09; 'stored': 0.10; 'library': 0.15; 'producing': 0.15; 'bug,': 0.16; 'fixing,': 0.16; 'imo.': 0.16; 'one)': 0.16; 'programmer,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reliably': 0.16; 'roy': 0.16; 'wrote:': 0.17; 'fix': 0.17; 'directory.': 0.17; '>>>': 0.18; '(or': 0.18; 'import': 0.21; 'programming': 0.23; "i've": 0.23; 'idea': 0.24; 'second': 0.24; 'script': 0.24; 'least': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'developers': 0.26; 'supported': 0.26; '(most': 0.27; 'core': 0.27; 'see,': 0.27; 'header:X-Complaints-To:1': 0.28; 'initial': 0.28; 'run': 0.28; 'post': 0.28; 'record': 0.28; 'inspect': 0.29; 'writes:': 0.29; 'case,': 0.29; 'definition': 0.29; '"the': 0.29; "i'm": 0.29; 'relative': 0.30; 'on,': 0.30; 'expect': 0.31; 'code': 0.31; 'gets': 0.32; 'file': 0.32; 'from:addr:yahoo.co.uk': 0.32; "skip:' 20": 0.32; 'could': 0.32; 'print': 0.32; '11,': 0.33; 'point,': 0.33; 'right?': 0.33; 'traceback': 0.33; 'to:addr :python-list': 0.33; 'or,': 0.34; 'wrong': 0.34; 'described': 0.35; 'path': 0.35; 'stable': 0.35; 'doing': 0.35; 'subject:?': 0.35; 'something': 0.35; 'received:org': 0.36; 'really': 0.36; 'but': 0.36; '(i.e.': 0.36; 'programmers': 0.36; 'should': 0.36; 'does': 0.37; 'being': 0.37; 'why': 0.37; 'far': 0.37; 'subject:: ': 0.38; 'mark': 0.38; 'fact': 0.38; 'object': 0.38; 'some': 0.38; 'nothing': 0.38; 'sure': 0.38; 'to:addr:python.org': 0.39; 'application': 0.40; 'where': 0.40; 'header:Received:5': 0.40; 'think': 0.40; 'your': 0.60; 'first': 0.61; 'different': 0.63; 'ever': 0.63; 'more': 0.63; 'behavior': 0.64; 'making': 0.64; 'following.': 0.65; 'learned': 0.65; 'smith': 0.71; 'gotten': 0.75; 'article': 0.78; 'is)': 0.84; 'pardon': 0.84; 'picture.': 0.84; 'start-up,': 0.84; 'officially': 0.91; 'subject:remember': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Mark Lawrence <breamoreboy@yahoo.co.uk>
Subject Re: Why doesn't Python remember the initial directory?
Date Mon, 20 Aug 2012 08:10:14 +0100
References <k0rj38$2gc$1@reader1.panix.com> <roy-CA6D77.17031119082012@news.panix.com> <k0s5iq$seh$1@reader1.panix.com>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host host-78-147-26-58.as13285.net
User-Agent Mozilla/5.0 (Windows NT 6.0; rv:14.0) Gecko/20120713 Thunderbird/14.0
In-Reply-To <k0s5iq$seh$1@reader1.panix.com>
X-Antivirus avast! (VPS 120819-1, 19/08/2012), Outbound message
X-Antivirus-Status Clean
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3540.1345446515.4697.python-list@python.org> (permalink)
Lines 84
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1345446515 news.xs4all.nl 6897 [2001:888:2000:d::a6]:40604
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:27467

Show key headers only | View raw


On 20/08/2012 02:57, kj 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?
>
>> More to the point, doing a chdir() is not something any library code
>> would do (at least not that I'm aware of), so if the directory changed,
>> it's because some application code did it.  In which case, you could
>> have just stored the working directory yourself.
>
> 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__.  That's a weakness, IMO.  One manifestation
> of this weakness is that os.chdir breaks inspect.getmodule, at
> least on Unix.  If you have some Unix system handy, you can try
> the following.  First change the argument to os.chdir below to some
> valid directory other than your working directory.  Then, run the
> script, making sure that you refer to it using a relative path.
> When I do this on my system (OS X + Python 2.7.3), the script bombs
> at the last print statement, because the second call to inspect.getmodule
> (though not the first one) returns None.
>
> import inspect
> import os
>
> frame = inspect.currentframe()
>
> print inspect.getmodule(frame).__name__
>
> os.chdir('/some/other/directory') # where '/some/other/directory' is
>                                    # different from the initial directory
>
> print inspect.getmodule(frame).__name__
>
> ...............
>
> % python demo.py
> python demo.py
> __main__
> Traceback (most recent call last):
>    File "demo.py", line 11, in <module>
>      print inspect.getmodule(frame).__name__
> AttributeError: 'NoneType' object has no attribute '__name__'
>
>
>
> 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.
>
> But, who am I kidding?  What needs fixing, right?  That's not a
> bug, that's a feature!  Etc.
>
> By now I have learned to expect that 99.99% of Python programmers
> will find that there's nothing wrong with behavior like the one
> described above, that it is in fact exactly As It Should Be, because,
> you see, since Python is the epitome of perfection, it follows
> inexorably that any flaw or shortcoming one may *perceive* in Python
> is only an *illusion*: the flaw or shortcoming is really in the
> benighted programmer, for having stupid ideas about programming
> (i.e. any idea that may entail that Python is not *gasp* perfect).
> Pardon my cynicism, but the general vibe from the replies I've
> gotten to my post (i.e. "if Python ain't got it, it means you don't
> need it") is entirely in line with these expectations.
>

I see, I see, I get the picture.  You're in the "The OS is flawed so I 
expect the Python core developers to do my work for me by producing code 
that gets around every known flaw in every supported OS" club.  Somehow 
I don't think that will happen.

-- 
Cheers.

Mark Lawrence.

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