How do I organize my Python application code?

Fredrik Lundh fredrik at pythonware.com
Thu Aug 14 04:37:11 EDT 2008


Dudeja, Rajat wrote:

> And my problem is that I don't have an understanding of how the code in
> Python is generally organized, in case my code spans multiple files,
> modules, etc. I've been using C/C++ althrough my life on Linux and
> Visaul Studio, so the way their code is organized in a group of header
> files, source files, etc, I'm looking for a similar way in Python way or
> an approach to organize my python GUI application code? 

A Python program consists of a script file (the py file you run to start 
the program), and usually one or more additional module files (py files 
that you import).  The latter can be organized in packages, where 
appropriate.   There's also a search path (sys.path) that you can modify 
in various ways (including from within the program) if you want to fetch 
modules from different locations.

That's all there is; there's no header files or declaration files or 
explicitly maintained object files etc; the program itself is just a 
bunch of Python files.

To learn more about this, the "modules" section in the tutorial is a 
good start:

     http://docs.python.org/tut/node8.html

Looking at the structure of a few existing projects might also be helpful.

</F>




More information about the Python-list mailing list