473,651 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python program organization

Hello all,

I have a few questions about the best way to organize a large Python
program. This would be a large program with a GUI interface, too large
to be put all in one script file by any sane person. I was wondering
about how a Python programmer should organize the multiple python source
files that will be needed by their program. Is it proper to break the
program up into modules and put all of the modules in a package even if
the modules would be of little or no use to others (such as the program
specific GUI code)? Would this package then go under Python's
site-packages directory when the program is installed? Would
distribution of a program like this use distutils?

Thank you,
Derek
Jul 18 '05 #1
7 2648
[Derek W]
Is it proper to break the program up into modules and put all of the
modules in a package even if the modules would be of little or no use
to others (such as the program specific GUI code)?
Hi, Derek. It looks proper to me. You might want to break a big
package into sub-packages, but all of it usually goes into a single
directory hierarchy.
Would this package then go under Python's site-packages directory when
the program is installed?
This is the most natural thing to do.
Would distribution of a program like this use distutils?


Why not? :-)

--
François Pinard http://www.iro.umontreal.ca/~pinard

Jul 18 '05 #2
Derek W <wh*****@NOSPAM cox.net> wrote in message news:<6fGZb.252 59$tM5.21166@fe d1read04>...
Hello all,
[snip....]Would this package then go under Python's
site-packages directory when the program is installed? Would
distribution of a program like this use distutils?

Thank you,
Derek


I'm a relative newbie and have only ever written medium sized (or
small)programs. .. *but* python will import modules from the same
directory as the main script is running. Several of my programs are
broken up into modules - and then all kept in the same directory.

Regards,
Fuzzyman

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #3
Derek W <wh*****@NOSPAM cox.net> wrote in message news:<6fGZb.252 59$tM5.21166@fe d1read04>...
Hello all,
[snip....]Would this package then go under Python's
site-packages directory when the program is installed? Would
distribution of a program like this use distutils?

Thank you,
Derek


I'm a relative newbie and have only ever written medium sized (or
small)programs. .. *but* python will import modules from the same
directory as the main script is running. Several of my programs are
broken up into modules - and then all kept in the same directory.

Regards,
Fuzzyman

http://www.voidspace.org.uk/atlantib...thonutils.html
Jul 18 '05 #4
François Pinard wrote:
[Derek W]

Is it proper to break the program up into modules and put all of the
modules in a package even if the modules would be of little or no use
to others (such as the program specific GUI code)?

Hi, Derek. It looks proper to me. You might want to break a big
package into sub-packages, but all of it usually goes into a single
directory hierarchy.

Would this package then go under Python's site-packages directory when
the program is installed?

This is the most natural thing to do.

Would distribution of a program like this use distutils?

Why not? :-)


François,

Thank you for replying to my post. I very much appreciate your input.
Great homepage by the way.

Thanks again,
Derek
Jul 18 '05 #5
Derek W <wh*****@NOSPAM cox.net> wrote in message news:<40******* *******@NOSPAMc ox.net>...
François Pinard wrote:
[Derek W]

Is it proper to break the program up into modules and put all of the
modules in a package even if the modules would be of little or no use
to others (such as the program specific GUI code)?

Hi, Derek. It looks proper to me. You might want to break a big
package into sub-packages, but all of it usually goes into a single
directory hierarchy.

Would this package then go under Python's site-packages directory when
the program is installed?

This is the most natural thing to do.

I disagree - if your program is an application it would be more normal
to put it in it's own directory in 'Program Files' - or whereever the
user specifies - rather than buryaing it somewhere in your python
distribution.

It's much better to save that directory for 'general' modules that are
going to be reused.

If all your 'modules' are in the same directory as the application
then python will import them fine wherever you put them.

Regards,

Fuzzy

http://www.voidspace.org.uk/atlantib...thonutils.html
Would distribution of a program like this use distutils?

Why not? :-)


François,

Thank you for replying to my post. I very much appreciate your input.
Great homepage by the way.

Thanks again,
Derek

Jul 18 '05 #6
> > > [Derek W]
>Is it proper to break the program up into modules and put all of
>the modules in a package even if the modules would be of little or
>no use to others (such as the program specific GUI code)? Would
>this package then go under Python's site-packages directory when
>the program is installed?
[François Pinard]
This is the most natural thing to do.

[Fuzzyman] I disagree - if your program is an application it would be more normal
to put it in it's own directory in 'Program Files' [...]
Oh! I'm not an MS user, but would presume `Program Files' is a bit like
`/usr/local/bin/' on Unix, or maybe the preferred place from where icons
on the desktop launch execution?

For a Python software system, best might be to install the bulk of it
into a package, or a hierarchy of packages, within `.../site-packages/'.
But of course, one always need a very small bootstrap along the search
PATH for executables whose sole purpose is importing the `main' module
from the installed packaged and launching it. This bootstrap is the
only fragment of the whole Python software system which is not compiled.
It's much better to save that directory for 'general' modules that are
going to be reused.


Each Python system in its own hierarchy within `.../site-packages/', but
all small bootstraps are kept together within a single directory.

For generic modules which do not pertain specifically to a Python
system, we created a special package named `Local'. This is useful in
our shop. Any Python system may import from Local, of course.

--
François Pinard http://www.iro.umontreal.ca/~pinard

Jul 18 '05 #7
Derek W <wh*****@NOSPAM cox.net> writes:
Hello all,

I have a few questions about the best way to organize a large Python
program. This would be a large program with a GUI interface, too
large to be put all in one script file by any sane person. I was
wondering about how a Python programmer should organize the multiple
python source files that will be needed by their program. Is it
proper to break the program up into modules and put all of the modules
in a package even if the modules would be of little or no use to
others (such as the program specific GUI code)? Would this package
then go under Python's site-packages directory when the program is
installed? Would distribution of a program like this use distutils?

Thank you,
Derek


1. General purpose

You should first think "model-view-controller", where the model is a
GUI-free compute engine which knows your persistant data. Then build
"view" modules which call the model's API. This should be bundled
with testsuites, convenience scripts, documentation, etc. These can
all go in the same package, and that in turn can be bundled using
distutils. Distutils in turn installs the package into site-packages.

For a utility which sets up a project, see:
http://www.seanet.com/~hgg9140/comp/...ythonproj.help

2. Larger

As projects get larger, you will find there are several "models".
E.g., for translations between various COTS tools. In that case, make
a separate package for each model (e.g., for the reader/writer adaptor
for each data format), and then another package for the project which
ties them together. The idea is to reduce unneeded cohesion -- make
the packages as isolated as you reasonably can so they are reusable in
other contexts.

3. Config controlled

If you have several variants of the packages, e.g., under CVS, then
you don't want to put them all in site-packages. Instead, check out
an internallly-consistent set of packages to a directory (e.g.,
"alpha", "beta", "prod"). Then, to assure the "imprts" find the right
modules and the right python version is run, make execution scripts
which do:

export PYTHONPATH=<pat h to working dir>/mypackage01:
<path to working dir>/mypackage02:
${PYTHONPATH}

PY=/usr/local/python2.3

${PY} <path to main script> <arguments as needed>

--
ha************@ boeing.com
6-6M21 BCA CompArch Design Engineering
Phone: (425) 342-0007
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

29
2457
by: Stephen Ferg | last post by:
I am a very satisfied user of Python and have been for number of years. I would never willing use another language. I wish all good things for Python, and that moves me to express some thoughts about Python's future prospects. I submit that the future expansion of Python usage is constrained by Python's lack of a CPAN-like facility, and I submit that without a CPyAN Python will never even get close to achieving the degree of...
75
4634
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the functions are simplified versions of the full featured methods for compiled regular expressions. Most non-trivial applications always use the compiled form UNQUOTE
267
10673
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at http://www.artima.com/weblogs/viewpost.jsp?thread=147358
0
8347
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8792
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8694
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8457
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1905
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.