Path?

Steve Holden steve at holdenweb.com
Wed Sep 6 20:16:27 EDT 2006


Dr. Pastor wrote:
> I installed Python 2.5 on Windows XP.
> I got the following system that works well.
> ---
> Python 2.5b3 (r25b3:51041, Aug  3 2006, 09:35:06) [MSC v.1310 32 bit 
> (Intel)] on
> win32 Type "copyright", "credits" or "license()" for more information.
> 
> IDLE 1.2b3
>  >>> import sys
>  >>> sys.path
> ['C:\\Python25\\Lib\\idlelib', 'C:\\WINDOWS\\system32\\python25.zip',
> 'C:\\Python25\\DLLs', 'C:\\Python25\\lib', 'C:\\Python25\\lib\\plat-win',
> 'C:\\Python25\\lib\\lib-tk', 'C:\\Python25', 
> 'C:\\Python25\\lib\\site-packages',
> 'C:\\Python25\\lib\\site-packages\\wx-2.6-msw-ansi']
>  >>>
> ---
> Question: How did I end up with the second item in path?

That was added as a part of the interpreter's initialisation.

> Is that a zip file?

Well, it would be ...

> There is no such a file in system32.

... if it existed! Python has been capable of importing from zip files 
for quite a while.

> What would be the correct way to set path to assist the search?

Well, that depends. If you want your modules to take precedence over 
similarly-named modules in the standard library (which can be risky if 
unexpected name clashes occur) then use

sys.path.insert(0, path)

where "path" holds the path of your choice. If you want to search other 
directories once the standard list has been exhausted then you should use

sys.path.append(path)

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb       http://holdenweb.blogspot.com
Recent Ramblings     http://del.icio.us/steve.holden




More information about the Python-list mailing list