Good programming style

Ben Finney bignose+hates-spam at benfinney.id.au
Sun Sep 14 18:41:22 EDT 2008


Astley Le Jasper <Astley.lejasper at gmail.com> writes:

> Is it best to have it all in one script or split it into per site
> scripts that can then be called by a manager script? If everything
> is in one script would you have per site functions to extract the
> data or generic function that contain vary slightly depending on the
> site, for example
> 
> import firstSiteScript
> import secondSiteScript

First: each of these things you're importing is a "module" in Python.
A script is what I prefer, for clarity, to call a "program": it's
intended to be executed independently as the top level of execution.

Second: please do yourself a favour and drop the camelCaseNames.
Follow PEP 8 <URL:http://www.python.org/dev/peps/pep-0008> for style
and naming in your Python code.

> firstsitedata = firstSiteScript.getData('search_str)
> secondsitedata = secondSiteScript.getData('search_str)
> etc etc

I'm presuming that there will be large areas of common functionality
between these different sites. On that basis, it's prbably best to
treat the differences as differences of *configuration* where
possible, instead of having separate modules for the entire site.

You might like to look at a web framework which gathers much of this
functionality together for you, and provides flexible ways to define
different sites in terms of those common elements
<URL:http://wiki.python.org/moin/WebFrameworks>.

-- 
 \       “Following fashion and the status quo is easy. Thinking about |
  `\        your users' lives and creating something practical is much |
_o__)                                harder.” —Ryan Singer, 2008-07-09 |
Ben Finney



More information about the Python-list mailing list