[Tutor] Sharing data between modules
johnf
jfabiani at yolo.com
Thu Oct 19 17:42:55 CEST 2006
On Thursday 19 October 2006 02:41, etrade.griffiths at dsl.pipex.com wrote:
> Hi
>
> just starting to get to grips with writing GUIs in Python using wxPython
> and not being a computer scientist, have a philosophical question about the
> "best" way to pass data between various modules. For example, I anticipate
> having one module to look after the GUI stuff where users can input data
> (either from the keyboard or file), another to process the data and
> (probably) a third to display the calculation results. Just not sure what
> the most efficient way of passing data between the various modules. I can
> think of 4 ways to do this, of which 1 is not possible in Python (I think).
>
> (1) via temp files: modules read to and write from temporary files
> (2) via function arguments: data passed from one module to another via
> argument lists. This seems the most logical but I have an irrational
> dislike of long argument lists. Could pass data objects (eg. C type
> structs) or dictionaries via the argument list but I don't think this gets
> around the "problem" of long argument lists and we now need pack/unpack
> type functions. Maybe this isn't a problem anyway?
> (3) via globals: AFAIK this is not recommended so we will move swiftly on
> (4) indirectly: thinking here of something along the FORTRAN COMMON blocks
> which (I think) Python doesn't have
>
> So, looks like it's a choice between (1) and (2) - or have I missed
> something obvious? What is the most "pythonic" way of doing this? Thanks
> in advance for any suggestions
What you are describing is N-Tier programming. Normally that is 3-Tier - user
interface, rules (business rules), and data access. There are several python
frameworks that assist with the N-tier setup. You might want to try 'Dabo'
or "PYTHONCARD". Using the frameworks you will not have to concern yourself
with how the modules are passing data (although all the source code is
available for review). Of course both frameworks assume the use of a data
store.
John
More information about the Tutor
mailing list