[Python-Dev] package imports, sys.path and os.chdir()
Christian Tismer
tismer at stackless.com
Sun Apr 29 13:14:42 CEST 2012
On 28.04.12 21:16, Brett Cannon wrote:
>
>
> On Sat, Apr 28, 2012 at 04:08, Nick Coghlan <ncoghlan at gmail.com
> <mailto:ncoghlan at gmail.com>> wrote:
>
> On Sat, Apr 28, 2012 at 6:00 AM, Brett Cannon <brett at python.org
> <mailto:brett at python.org>> wrote:
> > I'm personally in favour of changing the insertion of '' to
> sys.path to
> > inserting the cwd when the interpreter is launched.
>
> I'm not, because it breaks importing from the interactive prompt if
> you change directory after starting the session.
>
>
> Who does that? I mean what possible need do you have to start the
> interpreter in one directory, but then need to chdir somewhere else
> where you are doing your actual importing from, and in a way where you
> can't simply attach the directory you want to use into sys.path?
>
Well, it depends on which hat I'm wearing.
Scenario 1:
I am designing a big application. This application shall run without
problems,
with disambiguated imports, and by no means should hit anything that is not
meant to be imported.
In this case, I need to remove '' from sys.path and replace it with an
absolute entry.
Update: I see this works already unless "-c" and "-m" are present (hum).
Scenario 2:
I am playing with the application, want to try several modules, or even
several versions
of modules. I do use os.chdir() to get into a certain context, try
imports, remove them
again, chdir() to a different directory with a slightly changed module,
et cetera.
In this case, I need '' (or as has been mentioned '.') to have
flexibility for testing,
debugging and exploration.
These scenarios are both perfectly valid for their use case, but they
have pretty
different implication for imports, and especially for sys.path.
So the real question I was after was "can os.chdir() be freely used?"
It would be great to get "yes" or "no", but the answer is right now "it
depends".
cheers - chris
--
Christian Tismer :^)<mailto:tismer at stackless.com>
tismerysoft GmbH : Have a break! Take a ride on Python's
Karl-Liebknecht-Str. 121 : *Starship* http://starship.python.net/
14482 Potsdam : PGP key -> http://pgp.uni-mainz.de
work +49 173 24 18 776 mobile +49 173 24 18 776 fax n.a.
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20120429/cc6b87d3/attachment.html>
More information about the Python-Dev
mailing list