Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

Why doesn't Python remember the initial directory?

 

 

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded


nhodgson at iinet

Aug 20, 2012, 6:39 PM

Post #26 of 28 (69 views)
Permalink
Re: Why doesn't Python remember the initial directory? [In reply to]

Nobody:

> Maybe. On Unix, it's possible that the current directory no longer
> has a pathname.

Its also possible that you do not have permission to successfully
call getcwd. One example of this I have experienced is the OS X sandbox
where you can run Python starting in a directory where you have only
limited permissions.

getcwd works by calling readdir and lstat and looping up from the
current directory to the root to build the whole path so will break
without read permissions on directories:
http://www.opensource.apple.com/source/Libc/Libc-763.13/gen/FreeBSD/getcwd.c

Neil
--
http://mail.python.org/mailman/listinfo/python-list


no.email at nospam

Aug 20, 2012, 9:20 PM

Post #27 of 28 (69 views)
Permalink
Re: Why doesn't Python remember the initial directory? [In reply to]

alex23 <wuwei23 [at] gmail> writes:
> Oh my god, how DARE people with EXPERIENCE in a language challenge the
> PRECONCEPTIONS of an AMATEUR!!! HOW DARE THEY?!?!

+1 QOTW :)
--
http://mail.python.org/mailman/listinfo/python-list


johnroth1 at gmail

Aug 21, 2012, 1:35 PM

Post #28 of 28 (69 views)
Permalink
Re: Why doesn't Python remember the initial directory? [In reply to]

On Sunday, August 19, 2012 7:57:46 PM UTC-6, kj wrote:

> 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__.

If you want to find that, look up __main__ in sys.modules and then look at the __file__ attribute. You need to be a bit careful with this; the import machinery was rewritten for the upcoming 3.3 release, and there were several changes to the module information.

John Roth
--
http://mail.python.org/mailman/listinfo/python-list

First page Previous page 1 2 Next page Last page  View All Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.