[Pythonmac-SIG] warning: newbie ahead

Kevin Walzer kw at codebykevin.com
Sun Sep 16 00:03:47 CEST 2007


Paul Archibald wrote:

> What I am looking for is how to manage my PDE (Python Development  
> Environment) and project file so that I can write real programs,  
> saving, loading and executing, importing modules and calling  
> functions from various modules that I have written or otherwise  
> obtained. I have grabbed some code from various places on the web,  
> but I don't know where to put the files so that I an use them, except  
> for opening them in the editor and executing them, which is nice but  
> does not let me build real programs.

I'd take a closer look at the Python tutorial that comes with Idle 
(under the "help" menu--select "Python docs"). Section 6, "Modules," has 
some discussion on how modules are organized. The simplest way to import 
a module is to put your code in a file called "foo.py", launch Python 
from the same working directory where "foo.py" is stored, and then type 
in "import foo". All the bits in that module will be available to you. 
There are also standard directories, such as site-packages, where 
extension modules can be stored (this directory is 
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/ 

  on my system).

There's plenty of additional documentaiton on the net, and in basic 
Python books, about how Python libraries are organized.

Python doesn't really have the concept of a "project file"--I assume 
this is something generated by an IDE to keep track of where everything 
is stored? I know Xcode uses this approach. There may be Python IDE's 
that do this also; Idle does not, however, and this is what I use for 
most of my editing.

> 
> So, if you are building a program, where do you keep your sourcecode  
> for that progam, and how does Python know how to find it, and how do  
> you "link" modules together to make bigger programs?

I keep my code in two places: the current working directory of my 
application, or in site-packages (if I'm using a generic package).

> 
> There is a little info on configuration in the Mac Modules tutorial,  
> but it I still have some problems with .py scripts that seem to  
> execute okay but from which I cannot import any methods.
> 
> I am using IDLE w/Python 2.5, which does not have the "set scripts  
> folder" command like MacPython 2.4.

The command you are referring to was part of the old MacPython IDE, 
which is now obsolete. It was replaced as the standard editor in 
MacPython 2.5 by Idle.

> 
> Sorry this is a newbie question, but heck, I'm  newbie! And I work  
> alone, so I have nobody to ask or even look over the shoulder of to  
> see how its all set up.

I hope these answers are helpful. A complete introduction to Python is 
beyond what I can provide, but there are lots of resources out there, 
and Python should be a snap to pick up if you're experienced with C++ 
and Java.

--Kevin

-- 
Kevin Walzer
Code by Kevin
http://www.codebykevin.com


More information about the Pythonmac-SIG mailing list