Q: newbie win95 - python path navigation assignment strategies needed

Jason Cunliffe jasonic at nomadicsltd.com
Thu Apr 8 09:45:18 EDT 1999


Hello

I am very new to Python, though totally convinced of its genius and utility.
Been reading through, and downloading lots of great code, docs, etc. + the 3
books (now waiting for 'Learning Python'). But I seem to be stuck on a
_very_ basic issue. Please help, I need some guidance - over-the-shoulder;
heads-up on something I am not 'getting' yet...

system: Python 1.5.2b2 [MSC 32 bit (Intel)] on win32. 'Idle' by preference
:-)

I do not understand the relationships between modules, namespace, path and
the Python shell. When I am in the python shell at the prompt I can

>>> import sys
>>> sys.path
['C:\\Program Files\\Python\\Tools\\idle',
'C:\\PROGRA~1\\PYTHON\\TOOLS\\IDLE', 'C:\\Program Files\\Python\\win32',
'C:\\Program Files\\Python\\win32\\lib', 'C:\\Program Files\\Python',
'C:\\Program Files\\Python\\Pythonwin', 'C:\\Program
Files\\Python\\LLNLDistribution\\NUMERICAL\\LIB', 'C:\\Program
Files\\Python\\LLNLDistribution\\NUMERICAL\\PYDS', 'C:\\Program .....etc
etc...

and also
>>> import os
>>> os.getcwd()
'C:\\Program Files\\Python\\Tools\\idle'

But how and when do I need to change the working directory?
How and when do I need to navigate in the Python shell?
Should I be in the python shell or outside it to do this?
Do I need to even worry about it?
At what point in a session do I need to set the path?
Can I explicitly import a module by supplying a path prefix once and let
Python take care of the rest?
Is there some simple code to automate this?
Are these problems any different because I am using Idle?
What does Python do if it finds two modules with the same name both on
sys.path?

And what are the rules/caveats here about upper or lower case? for Win32
Python pathnames

I cannot seem to find a setcwd() command or similar.. Am I missing
something?

If add items to my path for example
>>> sys.path.append('c:\\mynewmodulepath')
this is good because I can then
>>> import mynewmodule

But when I save out my stuff, read or write from files, or import other
modules which may be located somewhere else, what strategy do you advise I
follow for path setting and manipulation? I have tried setting and changing
os.environ items. Is this the preferred way? for example:

os.environ['MY_DEMOS'] =  'c:\\downloads\\My_Demos'

I realize some of my confusion is because I using Win32 and not on a unix
box at the moment. I am champing at the Python bit because I keep stumbling
over this basic path cwd stuff.

Likewise everywhere it in docs and READMEs where it advises running python
scripts as executables (Unix) how do you advise I behave on Win95/98/NT?

I need to use Win95 at the moment for other purposes and am very keen to use
Python as the glue between apps on Win32 and other OSen (Irix, Linux).

Thanks in advance for any help.

- Jason






More information about the Python-list mailing list